Shelley Vohr
e19c13b87c
string_decoder: decode UTF-8 via StringBytes::Encode
...
StringDecoder used v8::String::NewFromUtf8() for UTF-8, while
Buffer#toString() goes through StringBytes::Encode(), which has
simdutf-backed ASCII, Latin-1 and UTF-16 paths and only falls back
to NewFromUtf8() for input that contains invalid sequences. Route
the decoder through the same function, so streams with
setEncoding('utf8') and readline decode at the same speed as
Buffer#toString(). U+FFFD replacement is unchanged because invalid
input still ends up in NewFromUtf8(), and the ERR_STRING_TOO_LONG
check is kept explicit so over-long input fails as before.
benchmark/string_decoder/string-decoder.js (encoding=utf8) and a
readline-over-pipe workload improve by 2-3x for chunks >= 1 KiB;
64 KiB newline-delimited JSON round trips over child stdio improve
by ~30% on the reading side alone.
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/65324
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
Reviewed-By: Daniel Lemire <daniel@lemire.me >
Reviewed-By: James M Snell <jasnell@gmail.com >
2026-08-18 16:34:12 +00:00
James M Snell
93644d5126
src: improve StringBytes error handling
...
PR-URL: https://github.com/nodejs/node/pull/57706
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2025-04-06 17:19:44 +00:00
James M Snell
cbedcd1696
src: improve error handling in string_bytes/decoder
...
PR-URL: https://github.com/nodejs/node/pull/56978
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2025-02-11 16:40:02 +00:00
Yagiz Nizipli
317d2450f9
src: modernize likely/unlikely hints
...
PR-URL: https://github.com/nodejs/node/pull/55155
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2024-09-30 18:04:16 +00:00
zhenweijin
8123be16a5
string_decoder: throw an error when writing a too long buffer
...
PR-URL: https://github.com/nodejs/node/pull/52215
Fixes: https://github.com/nodejs/node/issues/52214
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: theanarkh <theratliter@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-05-04 08:41:05 -07:00
legendecas
71ff89f929
src: rename internal module declaration as internal bindings
...
This is a continuation of the name reification on the internal bindings.
Renames NODE_MODULE_CONTEXT_AWARE_INTERNAL and
NODE_MODULE_EXTERNAL_REFERENCE to NODE_BINDING_CONTEXT_AWARE_INTERNAL
and NODE_BINDING_EXTERNAL_REFERENCE respectively.
PR-URL: https://github.com/nodejs/node/pull/45551
Refs: https://github.com/nodejs/node/issues/44036
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2022-11-29 00:23:08 +08:00
legendecas
a7e5b413ef
src: split property helpers from node::Environment
...
PR-URL: https://github.com/nodejs/node/pull/44056
Refs: https://github.com/nodejs/node/issues/42528
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Feng Yu <F3n67u@outlook.com >
2022-08-02 00:01:02 +08:00
Filip Skokan
f8ab632d56
buffer: add base64url encoding option
...
PR-URL: https://github.com/nodejs/node/pull/36952
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2021-01-18 12:08:20 +01:00
Michaël Zasso
11b34a916f
string_decoder: throw ERR_STRING_TOO_LONG for UTF-8
...
String::NewFromUtf8 doesn't generate an exception in V8 when the string
is too long but is guaranteed to return an empty MaybeLocal only in
that case. Generate a Node.js exception when it happens.
Fixes: https://github.com/nodejs/node/issues/35676
PR-URL: https://github.com/nodejs/node/pull/36661
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-12-31 15:40:01 +00:00
Joyee Cheung
7a447bcd54
src: snapshot node
...
This runs `lib/internal/bootstrap/node.js` before creating
the builtin snapshot and deserialize the loaders from the
snapshot in deserialization mode.
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:23:21 +08:00
Sam Roberts
b6bfc19378
src: remove util-inl.h from header files
...
Its intended that *-inl.h header files are only included into the src
files that call the inline methods. Explicitly include it into the files
that need it.
PR-URL: https://github.com/nodejs/node/pull/27631
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2019-05-13 13:43:26 -07:00
Sam Roberts
060d901f87
src: replace FromJust() with Check() when possible
...
FromJust() is often used not for its return value, but for its
side-effects. In these cases, Check() exists, and is more clear as to
the intent. From its comment:
To be used, where the actual value of the Maybe is not needed, like
Object::Set.
See: https://github.com/nodejs/node/pull/26929/files#r269256335
PR-URL: https://github.com/nodejs/node/pull/27162
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com >
2019-04-12 12:33:37 -07:00
Refael Ackermann
f2064dfc1f
src: de-lint header usage
...
PR-URL: https://github.com/nodejs/node/pull/26306
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2019-03-12 09:57:19 -04:00
Anna Henningsen
31975bbc88
src: allow not materializing ArrayBuffers from C++
...
Where appropriate, use a helper that wraps around
`ArrayBufferView::Buffer()` or `ArrayBufferView::CopyContents()`
rather than `Buffer::Data()`, as that may help to avoid materializing
the underlying `ArrayBuffer` when reading small typed arrays from C++.
This allows keeping the performance benefits of the faster creation of
heap-allocated small typed arrays in many cases.
PR-URL: https://github.com/nodejs/node/pull/26301
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-03-01 21:57:54 +01:00
Joyee Cheung
1838d00eba
src: reduce includes of node_internals.h
...
PR-URL: https://github.com/nodejs/node/pull/25507
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-01-21 07:54:42 +01:00
cjihrig
4e31a7f354
src: introduce DCHECK macro
...
This commit adds a DCHECK macro for consistency with the
other DCHECK_* macros.
PR-URL: https://github.com/nodejs/node/pull/25207
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2018-12-26 12:25:32 -05:00
cjihrig
c2b4269b77
src: use DCHECK_* macros where possible
...
PR-URL: https://github.com/nodejs/node/pull/25207
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2018-12-26 12:25:19 -05:00
Sam Roberts
0c65314e0e
src: fix type mismatch warnings from missing priv
...
Registration initialization functions are expected to have a 4th
argument, a void*, so add them where necessary to fix the warnings.
PR-URL: https://github.com/nodejs/node/pull/24737
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-12-03 19:44:15 -08:00
Anna Henningsen
06f6ac179c
string_decoder: fix number of replacement chars
...
Fixes: https://github.com/nodejs/node/issues/22626
PR-URL: https://github.com/nodejs/node/pull/22709
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-09-24 22:19:06 +02:00
Anna Henningsen
71f633a32f
src: allow UTF-16 in generic StringBytes decode call
...
This allows removing a number of special cases in other
parts of the code, at least one of which was incorrect
in expecting aligned input when that was not guaranteed.
Fixes: https://github.com/nodejs/node/issues/22358
PR-URL: https://github.com/nodejs/node/pull/22622
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2018-09-03 22:33:42 +02:00
Michaël Zasso
08aad66411
src,deps: add isolate parameter to String::Concat
...
Partially backport an upstream commit that deprecates String::Concat
without the isolate parameter. This overload has already been removed
in V8 7.0.
PR-URL: https://github.com/nodejs/node/pull/22521
Refs: https://github.com/v8/v8/commit/8a011b57d8b26e9cfe1c20a2ef26adb14be6ecc2
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
2018-08-28 14:11:20 +02:00
Tobias Nießen
39f209649f
src: add CHECK_NULL/CHECK_NOT_NULL macros
...
This change introduces CHECK_NULL and CHECK_NOT_NULL macros
similar to their definition in v8 and replaces instances of
CHECK/CHECK_EQ/CHECK_NE with these where it seems appropriate.
PR-URL: https://github.com/nodejs/node/pull/20914
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2018-05-26 12:29:31 +02:00
Anna Henningsen
180af17b52
string_decoder: reimplement in C++
...
Implement string decoder in C++. The perks are a decent speed boost
(for decoding, whereas creation show some performance degradation),
that this can now be used more easily to add native decoding support
to C++ streams and (arguably) more readable variable names.
PR-URL: https://github.com/nodejs/node/pull/18537
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2018-02-10 14:38:56 +01:00