From 17f9c2e35b0f0caa44a7674347886de7c5bd05aa Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 14 Apr 2014 05:11:27 +0000 Subject: [Allocator] Make the underlying allocator a template instead of an abstract interface. The only user of this functionality is the JIT memory manager and it is quite happy to have a custom type here. This removes a virtual function call and a lot of unnecessary abstraction from the common case where this is just a *very* thin vaneer around a call to malloc. Hopefully still no functionality changed here. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206149 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/AllocatorTest.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'unittests/Support') diff --git a/unittests/Support/AllocatorTest.cpp b/unittests/Support/AllocatorTest.cpp index bc39a149a0..0ba45d78c2 100644 --- a/unittests/Support/AllocatorTest.cpp +++ b/unittests/Support/AllocatorTest.cpp @@ -102,13 +102,13 @@ TEST(AllocatorTest, TestSmallSlabSize) { // Mock slab allocator that returns slabs aligned on 4096 bytes. There is no // easy portable way to do this, so this is kind of a hack. -class MockSlabAllocator : public SlabAllocator { - size_t LastSlabSize; +class MockSlabAllocator { + static size_t LastSlabSize; public: - virtual ~MockSlabAllocator() { } + ~MockSlabAllocator() { } - virtual void *Allocate(size_t Size) { + void *Allocate(size_t Size) { // Allocate space for the alignment, the slab, and a void* that goes right // before the slab. size_t Alignment = 4096; @@ -124,19 +124,20 @@ public: return Slab; } - virtual void Deallocate(void *Slab, size_t Size) { + void Deallocate(void *Slab, size_t Size) { free(((void**)Slab)[-1]); } - size_t GetLastSlabSize() { return LastSlabSize; } + static size_t GetLastSlabSize() { return LastSlabSize; } }; +size_t MockSlabAllocator::LastSlabSize = 0; + // Allocate a large-ish block with a really large alignment so that the // allocator will think that it has space, but after it does the alignment it // will not. TEST(AllocatorTest, TestBigAlignment) { - MockSlabAllocator SlabAlloc; - BumpPtrAllocator Alloc(SlabAlloc); + BumpPtrAllocatorImpl Alloc; // First allocate a tiny bit to ensure we have to re-align things. (void)Alloc.Allocate(1, 0); @@ -146,7 +147,7 @@ TEST(AllocatorTest, TestBigAlignment) { // We test that the last slab size is not the default 4096 byte slab, but // rather a custom sized slab that is larger. - EXPECT_GT(SlabAlloc.GetLastSlabSize(), 4096u); + EXPECT_GT(MockSlabAllocator::GetLastSlabSize(), 4096u); } } // anonymous namespace -- cgit v1.2.3