Skip to content

Commit 73a8b66

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

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

benchmark/buffers/buffer-from.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ const common = require('../common.js');
44
const assert = require('assert');
55
const bench = common.createBenchmark(main, {
66
source: [
7-
'array',
8-
'arraybuffer',
9-
'arraybuffer-middle',
10-
'buffer',
7+
// 'array',
8+
// 'arraybuffer',
9+
// 'arraybuffer-middle',
10+
// 'buffer',
1111
'string',
1212
'string-utf8',
1313
'string-base64',
14-
'object',
15-
'uint8array',
16-
'uint16array',
14+
// 'object',
15+
// 'uint8array',
16+
// 'uint16array',
1717
],
1818
len: [100, 2048],
1919
n: [8e5],

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)