test/osd: use stack for ObjectDesc::iterator::stack

better readability this way

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2020-08-24 17:11:40 +08:00
parent ca00bb7927
commit 7f32c70740
2 changed files with 13 additions and 15 deletions

View 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;
}

View 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),