[llvm] 4420ea7 - [StringMap] Move free into StringMapImpl dtor (NFC) (#91908)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 13 18:06:44 PDT 2024


Author: Nikita Popov
Date: 2024-05-14T10:06:41+09:00
New Revision: 4420ea7a4971eadad528c0cd609da471a7614422

URL: https://github.com/llvm/llvm-project/commit/4420ea7a4971eadad528c0cd609da471a7614422
DIFF: https://github.com/llvm/llvm-project/commit/4420ea7a4971eadad528c0cd609da471a7614422.diff

LOG: [StringMap] Move free into StringMapImpl dtor (NFC) (#91908)

StringMapImpl allocates the memory for the table, but does not have a
dtor that free it. Instead, StringMap (which inherits from
StringMapImpl) contains the free call. I don't really see a good reason
why this free is performed in the "wrong" class, so move it into
StringMapImpl.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/StringMap.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h
index daaf82654e094..9b58af7327391 100644
--- a/llvm/include/llvm/ADT/StringMap.h
+++ b/llvm/include/llvm/ADT/StringMap.h
@@ -53,6 +53,7 @@ class StringMapImpl {
   }
 
   StringMapImpl(unsigned InitSize, unsigned ItemSize);
+  ~StringMapImpl() { free(TheTable); }
   unsigned RehashTable(unsigned BucketNo = 0);
 
   /// LookupBucketFor - Look up the bucket that the specified string should end
@@ -203,7 +204,6 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
         }
       }
     }
-    free(TheTable);
   }
 
   using AllocTy::getAllocator;


        


More information about the llvm-commits mailing list