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: #26573
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and BridgeAR committed Mar 21, 2019
1 parent c97851d commit b05fbaa
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 @@ -859,6 +859,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 b05fbaa

Please sign in to comment.