Skip to content

Commit

Permalink
src: add fast path for equal size to Reallocate()
Browse files Browse the repository at this point in the history
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: nodejs#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]>
  • Loading branch information
addaleax authored and targos committed Mar 27, 2019
1 parent 581e1e2 commit d568134
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit d568134

Please sign in to comment.