]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: BitMapAreaList became a thin wrapper over std::vector.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Mar 2017 00:08:06 +0000 (01:08 +0100)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 29 Mar 2017 08:31:51 +0000 (10:31 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/os/bluestore/BitAllocator.cc
src/os/bluestore/BitAllocator.h
src/test/objectstore/BitAllocator_test.cc

index d2a2fb3149f609b8926223e7bd1dfb1259c7fe0d..b9a41b6bd1213ef4f1df09fc4d5e4f4ec29fc493 100644 (file)
@@ -624,24 +624,25 @@ void BitMapAreaIN::init(CephContext* const cct,
 
   m_child_size_blocks = level_factor;
 
-  BitMapArea **children = new BitMapArea*[num_child];
+  std::vector<BitMapArea*> 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<BitMapArea*> 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();
index 787ef6900d2d002226feab9e5f17a83cca7b5de3..4a5e94270801be8effa3d31a65f0dfdc779b7b64 100644 (file)
@@ -253,26 +253,20 @@ public:
 class BitMapAreaList {
 
 private:
-  BitMapArea **m_items;
-  int64_t m_num_items;
+  std::vector<BitMapArea*> m_items;
 
 public:
-  BitMapArea *get_nth_item(int64_t idx) {
-    return m_items[idx];
-  }
-
-   BitMapArea ** get_item_list() {
-    return m_items;
+  BitMapAreaList(std::vector<BitMapArea*>&& 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();
   }
 };
 
index a15eaa3bf46d0a585a9623455d9335a9c646edcd..fc6ca79b573facc9340ab44d3ccee6421f9392a7 100644 (file)
@@ -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<BitMapArea*> 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<BitMapArea*>(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;
 }