src: add fast path for equal size to Reallocate() · nodejs/node@26361d1 (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit 26361d1

addaleaxtargos

authored and

committed

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: #26573Reviewed-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

File tree

1 file changed

lines changed

1 file changed

lines changed

Original file line number Diff line number Diff line change
@@ -959,6 +959,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
959 959 }
960 960
961 961 char* Environment::Reallocate(char* data, size_t old_size, size_t size) {
962 +if (old_size == size) return data;
962 963 // If we know that the allocator is our ArrayBufferAllocator, we can let
963 964 // if reallocate directly.
964 965 if (isolate_data()->uses_node_allocator()) {