Skip to content

Commit c37f14a

Browse files
committed
buffer: rm createFromString and use fast Buffer.write
1 parent 298ff4f commit c37f14a

File tree

2 files changed

+1
-22
lines changed

2 files changed

+1
-22
lines changed

lib/buffer.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const {
5959
compare: _compare,
6060
compareOffset,
6161
copy: _copy,
62-
createFromString,
6362
fill: bindingFill,
6463
isAscii: bindingIsAscii,
6564
isUtf8: bindingIsUtf8,
@@ -444,19 +443,12 @@ function allocate(size) {
444443
function fromStringFast(string, ops) {
445444
const length = ops.byteLength(string);
446445

447-
if (length >= (Buffer.poolSize >>> 1))
448-
return createFromString(string, ops.encodingVal);
449-
450-
if (length > (poolSize - poolOffset))
451-
createPool();
452-
let b = new FastBuffer(allocPool, poolOffset, length);
446+
let b = allocate(length);
453447
const actual = ops.write(b, string, 0, length);
454448
if (actual !== length) {
455449
// byteLength() may overestimate. That's a rare case, though.
456450
b = new FastBuffer(allocPool, poolOffset, actual);
457451
}
458-
poolOffset += actual;
459-
alignPool();
460452
return b;
461453
}
462454

src/node_buffer.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,6 @@ MaybeLocal<Object> New(Environment* env,
530530

531531
namespace {
532532

533-
void CreateFromString(const FunctionCallbackInfo<Value>& args) {
534-
CHECK(args[0]->IsString());
535-
CHECK(args[1]->IsInt32());
536-
537-
enum encoding enc = static_cast<enum encoding>(args[1].As<Int32>()->Value());
538-
Local<Object> buf;
539-
if (New(args.GetIsolate(), args[0].As<String>(), enc).ToLocal(&buf))
540-
args.GetReturnValue().Set(buf);
541-
}
542-
543-
544533
template <encoding encoding>
545534
void StringSlice(const FunctionCallbackInfo<Value>& args) {
546535
Environment* env = Environment::GetCurrent(args);
@@ -1436,7 +1425,6 @@ void Initialize(Local<Object> target,
14361425
SetMethodNoSideEffect(context, target, "btoa", Btoa);
14371426

14381427
SetMethod(context, target, "setBufferPrototype", SetBufferPrototype);
1439-
SetMethodNoSideEffect(context, target, "createFromString", CreateFromString);
14401428

14411429
SetFastMethodNoSideEffect(context,
14421430
target,
@@ -1501,7 +1489,6 @@ void Initialize(Local<Object> target,
15011489

15021490
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
15031491
registry->Register(SetBufferPrototype);
1504-
registry->Register(CreateFromString);
15051492

15061493
registry->Register(SlowByteLengthUtf8);
15071494
registry->Register(fast_byte_length_utf8.GetTypeInfo());

0 commit comments

Comments
 (0)