diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-04-14 05:11:27 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-04-14 05:11:27 +0000 |
commit | 17f9c2e35b0f0caa44a7674347886de7c5bd05aa (patch) | |
tree | 6595232562ed912bc9d2bf13fadbd55d31433b02 /unittests | |
parent | e20c45d2d8d9c3ddf909babbd1013128685b70d2 (diff) | |
download | llvm-17f9c2e35b0f0caa44a7674347886de7c5bd05aa.tar.gz llvm-17f9c2e35b0f0caa44a7674347886de7c5bd05aa.tar.bz2 llvm-17f9c2e35b0f0caa44a7674347886de7c5bd05aa.tar.xz |
[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
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/AllocatorTest.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
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<MockSlabAllocator> 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 |