Skip to content

Commit b05fbaa

Browse files
addaleaxBridgeAR
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: nodejs#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 c97851d commit b05fbaa

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
@@ -859,6 +859,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
859859
}
860860

861861
char* Environment::Reallocate(char* data, size_t old_size, size_t size) {
862+
if (old_size == size) return data;
862863
// If we know that the allocator is our ArrayBufferAllocator, we can let
863864
// if reallocate directly.
864865
if (isolate_data()->uses_node_allocator()) {

0 commit comments

Comments
 (0)