From 26361d1a5fb0ce1a29f6f2b396f97733e98e0be3 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. PR-URL: https://github.com/nodejs/node/pull/26573 Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- src/env.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/env.cc b/src/env.cc index 3e88ab5390802a..fea03b70db07da 100644 --- a/src/env.cc +++ b/src/env.cc @@ -959,6 +959,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()) {