From 91d9d07c466aff89651d784377dae36338d063d1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 10 Mar 2019 21:45:17 +0000 Subject: [PATCH] src: add fast path for equal size to `Reallocate()` When old and new size match, we can skip the rest of the function, which makes sense in the case of embedders who do not use Node's allocator, as that would lead to needlessly allocating and freeing buffers of identical sizes. --- src/env.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/env.cc b/src/env.cc index ba3e63ad8db7c6..c747a952a340ea 100644 --- a/src/env.cc +++ b/src/env.cc @@ -923,6 +923,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate, } char* Environment::Reallocate(char* data, size_t old_size, size_t size) { + if (old_size == size) return data; // If we know that the allocator is our ArrayBufferAllocator, we can let // if reallocate directly. if (isolate_data()->uses_node_allocator()) {