Skip to content

Commit a647a40

Browse files
committed
buffer: Reallocate() instead of creating new backing store
1 parent d335487 commit a647a40

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/node_buffer.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,8 @@ MaybeLocal<Object> New(Isolate* isolate,
327327
CHECK(actual <= length);
328328

329329
if (LIKELY(actual > 0)) {
330-
if (actual < length) {
331-
std::unique_ptr<BackingStore> old_store = std::move(store);
332-
store = ArrayBuffer::NewBackingStore(isolate, actual);
333-
memcpy(static_cast<char*>(store->Data()),
334-
static_cast<char*>(old_store->Data()),
335-
actual);
336-
}
330+
if (actual < length)
331+
store = BackingStore::Reallocate(isolate, std::move(store), actual);
337332
Local<ArrayBuffer> buf = ArrayBuffer::New(isolate, std::move(store));
338333
Local<Object> obj;
339334
if (UNLIKELY(!New(isolate, buf, 0, actual).ToLocal(&obj)))

0 commit comments

Comments
 (0)