]> granicus.if.org Git - python/commitdiff
Issue #26588: Optimize tracemalloc_realloc()
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 08:08:08 +0000 (09:08 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 08:08:08 +0000 (09:08 +0100)
No need to remove the old trace if the memory block didn't move.

Modules/_tracemalloc.c

index 3d96860f53a210a28cde1c9f91f9300f906b0029..139b16963c92a4e3de18be1ee70b4c43d5208500 100644 (file)
@@ -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