Introduce needsCleanup() for APFloat and APInt.
authorManuel Klimek <klimek@google.com>
Mon, 3 Jun 2013 13:03:05 +0000 (13:03 +0000)
committerManuel Klimek <klimek@google.com>
Mon, 3 Jun 2013 13:03:05 +0000 (13:03 +0000)
This is needed in clang so one can check if the object needs the
destructor called after its memory was freed. This is useful when
creating many APInt/APFloat objects with placement new, where the
overhead of tracking the pointers for cleanup is significant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183100 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APFloat.h
include/llvm/ADT/APInt.h
lib/Support/APFloat.cpp

index 64e56a0ef6a0b1cedbf778d97d8df479fc8498a2..33f997e1734287fc82ef2b9191803f490f4a3a68 100644 (file)
@@ -201,6 +201,9 @@ public:
 
   /// @}
 
+  /// \brief Returns whether this instance allocated memory.
+  bool needsCleanup() const { return partCount() > 1; }
+
   /// \name Convenience "constructors"
   /// @{
 
index a9df4036be2d90047594e35b7cc560d1fe8b1331..e5797b8be238e45665e775711b1cd63665dfbefe 100644 (file)
@@ -293,7 +293,7 @@ public:
 
   /// \brief Destructor.
   ~APInt() {
-    if (!isSingleWord())
+    if (needsCleanup())
       delete[] pVal;
   }
 
@@ -303,6 +303,9 @@ public:
   ///  method Read).
   explicit APInt() : BitWidth(1) {}
 
+  /// \brief Returns whether this instance allocated memory.
+  bool needsCleanup() const { return !isSingleWord(); }
+
   /// Used to insert APInt objects, or objects that contain APInt objects, into
   ///  FoldingSets.
   void Profile(FoldingSetNodeID &id) const;
index 16586fbc9e8063c109371ad2fbef80252ef4a2c9..2ad66c5687c99ea50eacfb37c15d3ac0806177e0 100644 (file)
@@ -580,7 +580,7 @@ APFloat::initialize(const fltSemantics *ourSemantics)
 void
 APFloat::freeSignificand()
 {
-  if (partCount() > 1)
+  if (needsCleanup())
     delete [] significand.parts;
 }