BumpPtrAllocator: remove 'no slabs allocated yet' check
authorHans Wennborg <hans@hanshq.net>
Sun, 17 Aug 2014 18:31:18 +0000 (18:31 +0000)
committerHans Wennborg <hans@hanshq.net>
Sun, 17 Aug 2014 18:31:18 +0000 (18:31 +0000)
We already handle the no-slabs case when checking whether the current slab
is large enough: if no slabs have been allocated, CurPtr and End are both 0.
alignPtr(0), will still be 0, and so "if (Ptr + Size <= End)" fails.

Differential Revision: http://reviews.llvm.org/D4943

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215841 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Allocator.h
unittests/Support/AllocatorTest.cpp

index 7a7e4c0a13e2ee1f5052f619a7f69ac50d3991e0..f39fd10b0245708b8c5666b601c717ada6c4fe97 100644 (file)
@@ -201,9 +201,6 @@ public:
 
   /// \brief Allocate space at the specified alignment.
   void *Allocate(size_t Size, size_t Alignment) {
-    if (!CurPtr) // Start a new slab if we haven't allocated one already.
-      StartNewSlab();
-
     // Keep track of how many bytes we've allocated.
     BytesAllocated += Size;
 
index 0fc84c7613f30cb715d9c83fc3597e3a6248fcb7..dc92ff9ef038c7920e72235b4afd768e99bb64b3 100644 (file)
@@ -112,7 +112,7 @@ TEST(AllocatorTest, TestSmallSlabSize) {
   BumpPtrAllocator Alloc;
 
   Alloc.Allocate(8000, 0);
-  EXPECT_EQ(2U, Alloc.GetNumSlabs());
+  EXPECT_EQ(1U, Alloc.GetNumSlabs());
 }
 
 // Mock slab allocator that returns slabs aligned on 4096 bytes.  There is no