From: Allen Samuels Date: Sat, 3 Dec 2016 00:51:27 +0000 (-0800) Subject: mempool: Add string to mempool data types. X-Git-Tag: v12.0.0~181^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=78125f7dc60e1a5d05a922dab8a0d2c2327e1daa;p=ceph-ci.git mempool: Add string to mempool data types. Signed-off-by: Allen Samuels --- diff --git a/src/include/mempool.h b/src/include/mempool.h index a95ce57dab7..6d434e8dd17 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -366,23 +366,33 @@ public: static const mempool::pool_index_t id = mempool::mempool_##x; \ template \ using pool_allocator = mempool::pool_allocator; \ + \ + using string = std::basic_string, \ + pool_allocator>; \ + \ template > \ using map = std::map>>; \ + \ template > \ using multimap = std::multimap>>; \ + \ template > \ using set = std::set>; \ + \ template \ using list = std::list>; \ + \ template \ using vector = std::vector>; \ + \ template, \ typename eq = std::equal_to> \ using unordered_map = \ std::unordered_map>>; \ + \ inline size_t allocated_bytes() { \ return mempool::get_pool(id).allocated_bytes(); \ } \ diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index 4113c53d27e..e2a8895c3b6 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -277,6 +277,18 @@ TEST(mempool, bufferlist) ASSERT_GE(after, before + len); } +TEST(mempool, string_test) +{ + mempool::unittest_2::string s; + s.reserve(100); + EXPECT_GE(mempool::unittest_2::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination : + for (size_t i = 0; i < 10; ++i) { + s += '1'; + s.append(s); + EXPECT_GE(mempool::unittest_2::allocated_items(), s.capacity() + 1u); + } +} + int main(int argc, char **argv) { vector args;