From: Radoslaw Zarzynski Date: Thu, 2 Mar 2017 00:08:06 +0000 (+0100) Subject: os/bluestore: BitMapAreaList became a thin wrapper over std::vector. X-Git-Tag: v12.0.2~240^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ba028d412cbccf65b8a55823b7883aa1e5b1ec31;p=ceph.git os/bluestore: BitMapAreaList became a thin wrapper over std::vector. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index d2a2fb3149f6..b9a41b6bd121 100644 --- a/src/os/bluestore/BitAllocator.cc +++ b/src/os/bluestore/BitAllocator.cc @@ -624,24 +624,25 @@ void BitMapAreaIN::init(CephContext* const cct, m_child_size_blocks = level_factor; - BitMapArea **children = new BitMapArea*[num_child]; + std::vector children; + children.reserve(num_child); int i = 0; for (i = 0; i < num_child - 1; i++) { if (m_level <= 2) { - children[i] = new BitMapAreaLeaf(cct, m_child_size_blocks, i, def); + children.push_back(new BitMapAreaLeaf(cct, m_child_size_blocks, i, def)); } else { - children[i] = new BitMapAreaIN(cct, m_child_size_blocks, i, def); + children.push_back(new BitMapAreaIN(cct, m_child_size_blocks, i, def)); } total_blocks -= m_child_size_blocks; } int last_level = BitMapArea::get_level(cct, total_blocks); if (last_level == 1) { - children[i] = new BitMapAreaLeaf(cct, total_blocks, i, def); + children.push_back(new BitMapAreaLeaf(cct, total_blocks, i, def)); } else { - children[i] = new BitMapAreaIN(cct, total_blocks, i, def); + children.push_back(new BitMapAreaIN(cct, total_blocks, i, def)); } - BitMapAreaList *list = new BitMapAreaList(children, num_child); + BitMapAreaList *list = new BitMapAreaList(std::move(children)); m_child_list = list; m_num_child = num_child; } @@ -959,12 +960,13 @@ void BitMapAreaLeaf::init(CephContext* const cct, alloc_assert(num_child); m_child_size_blocks = total_blocks / num_child; - BitMapArea **children = new BitMapArea*[num_child]; + std::vector children; + children.reserve(num_child); for (int i = 0; i < num_child; i++) { - children[i] = new BitMapZone(cct, m_child_size_blocks, i, def); + children.emplace_back(new BitMapZone(cct, m_child_size_blocks, i, def)); } - BitMapAreaList *list = new BitMapAreaList(children, num_child); + BitMapAreaList *list = new BitMapAreaList(std::move(children)); m_child_list = list; m_num_child = num_child; @@ -982,7 +984,6 @@ BitMapAreaLeaf::~BitMapAreaLeaf() delete child; } - delete [] list->get_item_list(); delete list; unlock(); @@ -1077,16 +1078,6 @@ void BitMapAreaLeaf::free_blocks_int(int64_t start_block, int64_t num_blocks) } } -/* - * BitMapArea List related functions - */ -BitMapAreaList::BitMapAreaList(BitMapArea **list, int64_t len) -{ - m_items = list; - m_num_items = len; - return; -} - /* * Main allocator functions. */ @@ -1192,7 +1183,6 @@ BitAllocator::~BitAllocator() delete child; } - delete [] list->get_item_list(); delete list; unlock(); diff --git a/src/os/bluestore/BitAllocator.h b/src/os/bluestore/BitAllocator.h index 787ef6900d2d..4a5e94270801 100644 --- a/src/os/bluestore/BitAllocator.h +++ b/src/os/bluestore/BitAllocator.h @@ -253,26 +253,20 @@ public: class BitMapAreaList { private: - BitMapArea **m_items; - int64_t m_num_items; + std::vector m_items; public: - BitMapArea *get_nth_item(int64_t idx) { - return m_items[idx]; - } - - BitMapArea ** get_item_list() { - return m_items; + BitMapAreaList(std::vector&& m_items) + : m_items(std::move(m_items)) { } - int64_t size() { - return m_num_items; + BitMapArea *get_nth_item(const int64_t idx) { + return m_items[idx]; } - BitMapAreaList(BitMapArea **list, int64_t len); - BitMapAreaList(BitMapArea **list, int64_t len, int64_t marker); - BitMapArea **get_list() { - return m_items; + /* FIXME: we really should use size_t. */ + int64_t size() const { + return m_items.size(); } }; diff --git a/src/test/objectstore/BitAllocator_test.cc b/src/test/objectstore/BitAllocator_test.cc index a15eaa3bf46d..fc6ca79b573f 100644 --- a/src/test/objectstore/BitAllocator_test.cc +++ b/src/test/objectstore/BitAllocator_test.cc @@ -115,16 +115,18 @@ TEST(BitAllocator, test_bmap_iter) /* * BitMapArea Iter tests. */ - BitMapArea *area = NULL; - BitMapArea **children = new BitMapArea*[num_items]; + BitMapArea *area = nullptr; + std::vector children; + children.reserve(num_items); for (i = 0; i < num_items; i++) { - children[i] = new BitMapAreaLeaf( + children.emplace_back(new BitMapAreaLeaf( g_ceph_context, - BitMapArea::get_span_size(g_ceph_context), i, false); + BitMapArea::get_span_size(g_ceph_context), i, false)); } off = 0; - BitMapAreaList *area_list = new BitMapAreaList(children, num_items); + BitMapAreaList *area_list = \ + new BitMapAreaList(std::vector(children)); BmapEntityListIter area_iter = BmapEntityListIter( area_list, (int64_t) 0); i = off; @@ -160,7 +162,6 @@ TEST(BitAllocator, test_bmap_iter) for (i = 0; i < num_items; i++) delete children[i]; - delete[] children; delete area_list; }