diff options
author | Nick Kledzik <kledzik@apple.com> | 2014-01-28 19:21:27 +0000 |
---|---|---|
committer | Nick Kledzik <kledzik@apple.com> | 2014-01-28 19:21:27 +0000 |
commit | 15bcb9dc427d4c17eb44c050d9b9ce6befbfed64 (patch) | |
tree | c9f9aed04fc3214c478dd3535d01af76e6987c91 /llvm/unittests/Support/AllocatorTest.cpp | |
parent | 7aa9061ead8a1dec83ee7ec10b92b9d305a1d96f (diff) | |
download | bcm5719-llvm-15bcb9dc427d4c17eb44c050d9b9ce6befbfed64.tar.gz bcm5719-llvm-15bcb9dc427d4c17eb44c050d9b9ce6befbfed64.zip |
Add BumpPtrAllocator::allocateCopy() utilities
Makes it easy to use BumpPtrAllocator to make a copy of StringRef strings.
llvm-svn: 200331
Diffstat (limited to 'llvm/unittests/Support/AllocatorTest.cpp')
-rw-r--r-- | llvm/unittests/Support/AllocatorTest.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/unittests/Support/AllocatorTest.cpp b/llvm/unittests/Support/AllocatorTest.cpp index cb9fa430369..43ce0c86bee 100644 --- a/llvm/unittests/Support/AllocatorTest.cpp +++ b/llvm/unittests/Support/AllocatorTest.cpp @@ -147,4 +147,32 @@ TEST(AllocatorTest, TestBigAlignment) { EXPECT_LE(Ptr + 3000, ((uintptr_t)Slab) + Slab->Size); } +TEST(AllocatorTest, CopyStringRef) { + BumpPtrAllocator Alloc; + StringRef Str1 = "hello"; + StringRef Str2 = "bye"; + StringRef Str1c = Alloc.allocateCopy(Str1); + StringRef Str2c = Alloc.allocateCopy(Str2); + EXPECT_TRUE(Str1.equals(Str1c)); + EXPECT_NE(Str1.data(), Str1c.data()); + EXPECT_TRUE(Str2.equals(Str2c)); + EXPECT_NE(Str2.data(), Str2c.data()); +} + +TEST(AllocatorTest, CopyArrayRef) { + BumpPtrAllocator Alloc; + static const uint16_t Words1[] = { 1, 4, 200, 37 }; + ArrayRef<uint16_t> Array1 = makeArrayRef(Words1, 4); + static const uint16_t Words2[] = { 11, 4003, 67, 64000, 13 }; + ArrayRef<uint16_t> Array2 = makeArrayRef(Words2, 5); + ArrayRef<uint16_t> Array1c = Alloc.allocateCopy(Array1); + ArrayRef<uint16_t> Array2c = Alloc.allocateCopy(Array2); + EXPECT_TRUE(Array1.equals(Array1c)); + EXPECT_NE(Array1.data(), Array1c.data()); + EXPECT_TRUE(Array2.equals(Array2c)); + EXPECT_NE(Array2.data(), Array2c.data()); +} + + + } // anonymous namespace |