[cfe-commits] r83884 - /cfe/trunk/include/clang/Analysis/Support/BumpVector.h

Ted Kremenek kremenek at apple.com
Mon Oct 12 12:54:18 PDT 2009


Author: kremenek
Date: Mon Oct 12 14:54:17 2009
New Revision: 83884

URL: http://llvm.org/viewvc/llvm-project?rev=83884&view=rev
Log:
Allow BumpVectorContext to conditionally own the underlying BumpPtrAllocator.

Modified:
    cfe/trunk/include/clang/Analysis/Support/BumpVector.h

Modified: cfe/trunk/include/clang/Analysis/Support/BumpVector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Support/BumpVector.h?rev=83884&r1=83883&r2=83884&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Support/BumpVector.h (original)
+++ cfe/trunk/include/clang/Analysis/Support/BumpVector.h Mon Oct 12 14:54:17 2009
@@ -21,14 +21,29 @@
 
 #include "llvm/Support/type_traits.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/ADT/PointerIntPair.h"
 #include <algorithm>
 
 namespace clang {
   
 class BumpVectorContext {
-  llvm::BumpPtrAllocator Alloc;
+  llvm::PointerIntPair<llvm::BumpPtrAllocator*, 1, bool> Alloc;
 public:
-  llvm::BumpPtrAllocator &getAllocator() { return Alloc; }
+  /// Construct a new BumpVectorContext that creates a new BumpPtrAllocator
+  /// and destroys it when the BumpVectorContext object is destroyed.
+  BumpVectorContext() : Alloc(new llvm::BumpPtrAllocator(), true) {}
+  
+  /// Construct a new BumpVectorContext that reuses an existing
+  /// BumpPtrAllocator.  This BumpPtrAllocator is not destroyed when the
+  /// BumpVectorContext object is destroyed.
+  BumpVectorContext(llvm::BumpPtrAllocator &A) : Alloc(&A, false) {}
+  
+  ~BumpVectorContext() {
+    if (Alloc.getInt())
+      delete Alloc.getPointer();
+  }
+  
+  llvm::BumpPtrAllocator &getAllocator() { return *Alloc.getPointer(); }
 };
   
 template<typename T>





More information about the cfe-commits mailing list