diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-02-11 23:11:12 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-02-11 23:11:12 +0000 |
commit | a618f82c9fdbe869b41581f00ae357e1b22302d1 (patch) | |
tree | 8e9885a954e5354e163ed61738b9e677fd005339 /include/llvm/ADT/ImmutableSet.h | |
parent | 8c77ff9f8536464a92dad673c82c78daa62e3111 (diff) | |
download | external_llvm-a618f82c9fdbe869b41581f00ae357e1b22302d1.zip external_llvm-a618f82c9fdbe869b41581f00ae357e1b22302d1.tar.gz external_llvm-a618f82c9fdbe869b41581f00ae357e1b22302d1.tar.bz2 |
The factories for ImutAVLTree/ImmutableSet/ImmutableMap now take an (optional)
BumpPtrAllocator argument to their constructors. This BumpPtrAllocator
will be used to allocate trees. If no BumpPtrAllocator is provided, one
is created (as before).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46975 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/ImmutableSet.h')
-rw-r--r-- | include/llvm/ADT/ImmutableSet.h | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/include/llvm/ADT/ImmutableSet.h b/include/llvm/ADT/ImmutableSet.h index c339e3d..717ec98 100644 --- a/include/llvm/ADT/ImmutableSet.h +++ b/include/llvm/ADT/ImmutableSet.h @@ -16,6 +16,7 @@ #include "llvm/Support/Allocator.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/Support/DataTypes.h" #include <cassert> namespace llvm { @@ -334,15 +335,31 @@ class ImutAVLFactory { typedef FoldingSet<TreeTy> CacheTy; - CacheTy Cache; - BumpPtrAllocator Allocator; + CacheTy Cache; + uintptr_t Allocator; + + bool ownsAllocator() const { + return Allocator & 0x1 ? false : true; + } + + BumpPtrAllocator& getAllocator() const { + return *reinterpret_cast<BumpPtrAllocator*>(Allocator & ~0x1); + } //===--------------------------------------------------===// // Public interface. //===--------------------------------------------------===// public: - ImutAVLFactory() {} + ImutAVLFactory() + : Allocator(reinterpret_cast<uintptr_t>(new BumpPtrAllocator())) {} + + ImutAVLFactory(BumpPtrAllocator& Alloc) + : Allocator(reinterpret_cast<uintptr_t>(&Alloc) | 0x1) {} + + ~ImutAVLFactory() { + if (ownsAllocator()) delete &getAllocator(); + } TreeTy* Add(TreeTy* T, value_type_ref V) { T = Add_internal(V,T); @@ -358,8 +375,6 @@ public: TreeTy* GetEmptyTree() const { return NULL; } - BumpPtrAllocator& getAllocator() { return Allocator; } - //===--------------------------------------------------===// // A bunch of quick helper functions used for reasoning // about the properties of trees and their children. @@ -450,7 +465,8 @@ private: // Create it. // Allocate the new tree node and insert it into the cache. - TreeTy* T = (TreeTy*) Allocator.Allocate<TreeTy>(); + BumpPtrAllocator& A = getAllocator(); + TreeTy* T = (TreeTy*) A.Allocate<TreeTy>(); new (T) TreeTy(L,R,V,IncrementHeight(L,R)); // We do not insert 'T' into the FoldingSet here. This is because @@ -930,6 +946,9 @@ public: public: Factory() {} + Factory(BumpPtrAllocator& Alloc) + : F(Alloc) {} + /// GetEmptySet - Returns an immutable set that contains no elements. ImmutableSet GetEmptySet() { return ImmutableSet(F.GetEmptyTree()); } |