From: Victor Stinner Date: Wed, 23 Mar 2016 08:08:08 +0000 (+0100) Subject: Issue #26588: Optimize tracemalloc_realloc() X-Git-Tag: v3.6.0a1~389 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42bcf37fcffa65592e401c43aa8c0190452b28b0;p=python Issue #26588: Optimize tracemalloc_realloc() No need to remove the old trace if the memory block didn't move. --- diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 3d96860f53..139b16963c 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -633,7 +633,12 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size) /* an existing memory block has been resized */ TABLES_LOCK(); - REMOVE_TRACE(ptr); + + /* tracemalloc_add_trace() updates the trace if there is already + a trace at address (domain, ptr2) */ + if (ptr2 != ptr) { + REMOVE_TRACE(ptr); + } if (ADD_TRACE(ptr2, new_size) < 0) { /* Memory allocation failed. The error cannot be reported to