Skip to content

Commit 26361d1

Browse files
addaleaxtargos
authored andcommitted
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: #26573 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b552139 commit 26361d1

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Diff for: src/env.cc

+1
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
959959
}
960960

961961
char* Environment::Reallocate(char* data, size_t old_size, size_t size) {
962+
if (old_size == size) return data;
962963
// If we know that the allocator is our ArrayBufferAllocator, we can let
963964
// if reallocate directly.
964965
if (isolate_data()->uses_node_allocator()) {

0 commit comments

Comments
 (0)