summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-09-08 00:02:17 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-09-08 00:02:17 +0000
commitee8d9a0e81eb165a91c126ba1551ce60d3d6a293 (patch)
tree648ba2ecf200ff8ef106a5c05a1735c8bc7c71f2 /llvm
parentcef2c0efcc664eb0d8d907c6d0e1a8b7f9930380 (diff)
downloadbcm5719-llvm-ee8d9a0e81eb165a91c126ba1551ce60d3d6a293.tar.gz
bcm5719-llvm-ee8d9a0e81eb165a91c126ba1551ce60d3d6a293.zip
Smarter Reset(). Instead of deallocating all memory regions and reallocate the
first region, just deallocate all but the last region in the list. llvm-svn: 41782
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Support/Allocator.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/llvm/lib/Support/Allocator.cpp b/llvm/lib/Support/Allocator.cpp
index e68c3e26c7d..7c727b9435b 100644
--- a/llvm/lib/Support/Allocator.cpp
+++ b/llvm/lib/Support/Allocator.cpp
@@ -68,14 +68,25 @@ public:
return NewRegion->Allocate(AllocSize, Alignment, RegPtr);
}
- /// Deallocate - Release all memory for this region to the system.
- ///
+ /// Deallocate - Recursively release all memory for this and its next regions
+ /// to the system.
void Deallocate() {
MemRegion *next = Next;
free(this);
if (next)
next->Deallocate();
}
+
+ /// DeallocateAllButLast - Recursively release all memory for this and its
+ /// next regions to the system stopping at the last region in the list.
+ /// Returns the pointer to the last region.
+ MemRegion *DeallocateAllButLast() {
+ MemRegion *next = Next;
+ if (!next)
+ return this;
+ free(this);
+ return next->DeallocateAllButLast();
+ }
};
}
@@ -93,9 +104,10 @@ BumpPtrAllocator::~BumpPtrAllocator() {
}
void BumpPtrAllocator::Reset() {
- ((MemRegion*)TheMemory)->Deallocate();
- TheMemory = malloc(4096);
- ((MemRegion*)TheMemory)->Init(4096, 1, 0);
+ MemRegion *MRP = (MemRegion*)TheMemory;
+ MRP = MRP->DeallocateAllButLast();
+ MRP->Init(4096, 1, 0);
+ TheMemory = MRP;
}
void *BumpPtrAllocator::Allocate(unsigned Size, unsigned Align) {
OpenPOWER on IntegriCloud