Skip to content

Commit 26361d1

Browse files
addaleaxtargos
authored andcommittedMar 27, 2019
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 <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>
1 parent b552139 commit 26361d1

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed
 

‎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)
Please sign in to comment.