]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/osd: use stack for ObjectDesc::iterator::stack
authorKefu Chai <kchai@redhat.com>
Mon, 24 Aug 2020 09:11:40 +0000 (17:11 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 30 Aug 2020 10:34:17 +0000 (18:34 +0800)
better readability this way

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/osd/Object.cc
src/test/osd/Object.h

index 12f946f5650b2272de80bbdcfb9b1686edfd7dc8..9d914abd7944debbc8a60e3a2fbcb6732e608f4d 100644 (file)
@@ -82,28 +82,23 @@ void VarLenGenerator::get_ranges_map(
 }
 
 void ObjectDesc::iterator::adjust_stack() {
-  while (!stack.empty() && pos >= stack.front().second.next) {
-    ceph_assert(pos == stack.front().second.next);
-    size = stack.front().second.size;
-    current = stack.front().first;
-    stack.pop_front();
+  while (!stack.empty() && pos >= stack.top().second.next) {
+    ceph_assert(pos == stack.top().second.next);
+    size = stack.top().second.size;
+    current = stack.top().first;
+    stack.pop();
   }
 
   if (stack.empty()) {
     cur_valid_till = std::numeric_limits<uint64_t>::max();
   } else {
-    cur_valid_till = stack.front().second.next;
+    cur_valid_till = stack.top().second.next;
   }
 
   while (current != layers.end() && !current->covers(pos)) {
     uint64_t next = current->next(pos);
     if (next < cur_valid_till) {
-      stack.push_front(
-       make_pair(
-         current,
-         StackState{next, size}
-         )
-       );
+      stack.emplace(current, StackState{next, size});
       cur_valid_till = next;
     }
 
index 9de1e83af0d1cf9856a4c6bc0131e3a095fec8ca..a78a598236d025df326f849c2fca42349d331f6e 100644 (file)
@@ -5,6 +5,7 @@
 #include <list>
 #include <map>
 #include <set>
+#include <stack>
 #include <random>
 
 #ifndef OBJECT_H
@@ -369,14 +370,16 @@ public:
          std::numeric_limits<uint64_t>::max();
       }
     };
-    std::list<ContState> layers;
+    // from latest to earliest
+    using layers_t = std::vector<ContState>;
+    layers_t layers;
 
     struct StackState {
       const uint64_t next;
       const uint64_t size;
     };
-    std::list<std::pair<std::list<ContState>::iterator, StackState> > stack;
-    std::list<ContState>::iterator current;
+    std::stack<std::pair<layers_t::iterator, StackState> > stack;
+    layers_t::iterator current;
 
     explicit iterator(ObjectDesc &obj) :
       pos(0),