From 73a8b667b6a08a7ba64a1bbbdc33935b98ce9cc9 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 12 Aug 2024 08:04:21 +0200 Subject: [PATCH] buffer: rm createFromString and use fast Buffer.write --- benchmark/buffers/buffer-from.js | 14 +++++++------- lib/buffer.js | 10 +--------- src/node_buffer.cc | 13 ------------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/benchmark/buffers/buffer-from.js b/benchmark/buffers/buffer-from.js index 3b88fe3893d327..59440bc891677f 100644 --- a/benchmark/buffers/buffer-from.js +++ b/benchmark/buffers/buffer-from.js @@ -4,16 +4,16 @@ const common = require('../common.js'); const assert = require('assert'); const bench = common.createBenchmark(main, { source: [ - 'array', - 'arraybuffer', - 'arraybuffer-middle', - 'buffer', + // 'array', + // 'arraybuffer', + // 'arraybuffer-middle', + // 'buffer', 'string', 'string-utf8', 'string-base64', - 'object', - 'uint8array', - 'uint16array', + // 'object', + // 'uint8array', + // 'uint16array', ], len: [100, 2048], n: [8e5], diff --git a/lib/buffer.js b/lib/buffer.js index 4e6031afdb3919..7d1c46bb76fc06 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -59,7 +59,6 @@ const { compare: _compare, compareOffset, copy: _copy, - createFromString, fill: bindingFill, isAscii: bindingIsAscii, isUtf8: bindingIsUtf8, @@ -444,19 +443,12 @@ function allocate(size) { function fromStringFast(string, ops) { const length = ops.byteLength(string); - if (length >= (Buffer.poolSize >>> 1)) - return createFromString(string, ops.encodingVal); - - if (length > (poolSize - poolOffset)) - createPool(); - let b = new FastBuffer(allocPool, poolOffset, length); + let b = allocate(length); const actual = ops.write(b, string, 0, length); if (actual !== length) { // byteLength() may overestimate. That's a rare case, though. b = new FastBuffer(allocPool, poolOffset, actual); } - poolOffset += actual; - alignPool(); return b; } diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 6e141b974131cc..d8fce1a8e8106a 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -530,17 +530,6 @@ MaybeLocal New(Environment* env, namespace { -void CreateFromString(const FunctionCallbackInfo& args) { - CHECK(args[0]->IsString()); - CHECK(args[1]->IsInt32()); - - enum encoding enc = static_cast(args[1].As()->Value()); - Local buf; - if (New(args.GetIsolate(), args[0].As(), enc).ToLocal(&buf)) - args.GetReturnValue().Set(buf); -} - - template void StringSlice(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -1436,7 +1425,6 @@ void Initialize(Local target, SetMethodNoSideEffect(context, target, "btoa", Btoa); SetMethod(context, target, "setBufferPrototype", SetBufferPrototype); - SetMethodNoSideEffect(context, target, "createFromString", CreateFromString); SetFastMethodNoSideEffect(context, target, @@ -1501,7 +1489,6 @@ void Initialize(Local target, void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(SetBufferPrototype); - registry->Register(CreateFromString); registry->Register(SlowByteLengthUtf8); registry->Register(fast_byte_length_utf8.GetTypeInfo());