[llvm-commits] [llvm] r41782 - /llvm/trunk/lib/Support/Allocator.cpp

Evan Cheng evan.cheng at apple.com
Fri Sep 7 17:02:17 PDT 2007


Author: evancheng
Date: Fri Sep  7 19:02:17 2007
New Revision: 41782

URL: http://llvm.org/viewvc/llvm-project?rev=41782&view=rev
Log:
Smarter Reset(). Instead of deallocating all memory regions and reallocate the
first region, just deallocate all but the last region in the list.

Modified:
    llvm/trunk/lib/Support/Allocator.cpp

Modified: llvm/trunk/lib/Support/Allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Allocator.cpp?rev=41782&r1=41781&r2=41782&view=diff

==============================================================================
--- llvm/trunk/lib/Support/Allocator.cpp (original)
+++ llvm/trunk/lib/Support/Allocator.cpp Fri Sep  7 19:02:17 2007
@@ -68,14 +68,25 @@
     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 @@
 }
 
 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) {





More information about the llvm-commits mailing list