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
This commit is contained in:
Ted Kremenek 2008-02-11 23:11:12 +00:00
parent 8c77ff9f85
commit a618f82c9f
2 changed files with 28 additions and 6 deletions

View File

@ -84,6 +84,9 @@ public:
public:
Factory() {}
Factory(BumpPtrAllocator& Alloc)
: F(Alloc) {}
ImmutableMap GetEmptyMap() { return ImmutableMap(F.GetEmptyTree()); }
ImmutableMap Add(ImmutableMap Old, key_type_ref K, data_type_ref D) {

View File

@ -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()); }