Skip to content

Commit c705a5d

Browse files
committed
buffer: revert toHex in favour of nbytes HexEncode update
Remove V8 Uint8Array.prototype.toHex() path for Buffer.toString('hex') in favour of the upcoming nbytes HexEncode improvement (nodejs/nbytes#12) which is ~3x faster through the existing C++ hexSlice path. Refs: nodejs/nbytes#12
1 parent 01ba74f commit c705a5d

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

lib/buffer.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,8 @@ const {
5151
TypedArrayPrototypeGetLength,
5252
TypedArrayPrototypeSet,
5353
Uint8Array,
54-
Uint8ArrayPrototype,
55-
uncurryThis,
5654
} = primordials;
5755

58-
// Lazily initialized: toHex is installed by InitializeExperimentalGlobal()
59-
// (skipped during snapshot creation) and may be disabled with --no-js-base-64.
60-
let Uint8ArrayPrototypeToHex;
61-
function ensureUint8ArrayToHex() {
62-
if (Uint8ArrayPrototypeToHex === undefined) {
63-
Uint8ArrayPrototypeToHex = Uint8ArrayPrototype.toHex ?
64-
uncurryThis(Uint8ArrayPrototype.toHex) : null;
65-
}
66-
}
67-
6856
const {
6957
byteLengthUtf8,
7058
compare: _compare,
@@ -682,18 +670,6 @@ function base64ByteLength(str, bytes) {
682670
return (bytes * 3) >>> 2;
683671
}
684672

685-
function hexSliceToHex(buf, start, end) {
686-
ensureUint8ArrayToHex();
687-
// Fall back to C++ when toHex is unavailable or the result would exceed
688-
// kStringMaxLength (so the correct ERR_STRING_TOO_LONG error is thrown).
689-
if (Uint8ArrayPrototypeToHex === null || (end - start) * 2 > kStringMaxLength)
690-
return hexSlice(buf, start, end);
691-
return Uint8ArrayPrototypeToHex(
692-
new Uint8Array(TypedArrayPrototypeGetBuffer(buf),
693-
TypedArrayPrototypeGetByteOffset(buf) + start,
694-
end - start));
695-
}
696-
697673
const encodingOps = {
698674
utf8: {
699675
encoding: 'utf8',
@@ -771,7 +747,7 @@ const encodingOps = {
771747
encodingVal: encodingsMap.hex,
772748
byteLength: (string) => string.length >>> 1,
773749
write: hexWrite,
774-
slice: hexSliceToHex,
750+
slice: hexSlice,
775751
indexOf: (buf, val, byteOffset, dir) =>
776752
indexOfBuffer(buf,
777753
fromStringFast(val, encodingOps.hex),

0 commit comments

Comments
 (0)