Remove now redudantant 'Iterator.next()' care in TrackIterator

With Daniel's fix, this is no longer needed! Hooray!
custom
jacqueline 11 months ago
parent 23a5d26e8a
commit 661cc976a1
  1. 15
      src/tangara/database/database.cpp

@ -63,8 +63,8 @@ static const char kKeyTrackId[] = "next_track_id";
static std::atomic<bool> sIsDbOpen(false); static std::atomic<bool> sIsDbOpen(false);
static auto CreateNewDatabase(leveldb::Options& options, static auto CreateNewDatabase(leveldb::Options& options, locale::ICollator& col)
locale::ICollator& col) -> leveldb::DB* { -> leveldb::DB* {
Database::Destroy(); Database::Destroy();
leveldb::DB* db; leveldb::DB* db;
options.create_if_missing = true; options.create_if_missing = true;
@ -759,25 +759,18 @@ auto Iterator::count() const -> size_t {
TrackIterator::TrackIterator(const Iterator& it) : db_(it.db_), levels_() { TrackIterator::TrackIterator(const Iterator& it) : db_(it.db_), levels_() {
levels_.push_back(it); levels_.push_back(it);
next(false); next();
} }
auto TrackIterator::next() -> void { auto TrackIterator::next() -> void {
next(true);
}
auto TrackIterator::next(bool advance) -> void {
while (!levels_.empty()) { while (!levels_.empty()) {
if (advance) {
levels_.back().next(); levels_.back().next();
}
auto& cur = levels_.back().value(); auto& cur = levels_.back().value();
if (!cur) { if (!cur) {
// The current top iterator is out of tracks. Pop it, and move the parent // The current top iterator is out of tracks. Pop it, and move the parent
// to the next item. // to the next item.
levels_.pop_back(); levels_.pop_back();
advance = true;
} else if (std::holds_alternative<IndexKey::Header>(cur->contents())) { } else if (std::holds_alternative<IndexKey::Header>(cur->contents())) {
// This record is a branch. Push a new iterator. // This record is a branch. Push a new iterator.
auto key = std::get<IndexKey::Header>(cur->contents()); auto key = std::get<IndexKey::Header>(cur->contents());
@ -786,8 +779,6 @@ auto TrackIterator::next(bool advance) -> void {
return; return;
} }
levels_.emplace_back(db, key); levels_.emplace_back(db, key);
// Don't skip the first value of the new level.
advance = false;
} else if (std::holds_alternative<TrackId>(cur->contents())) { } else if (std::holds_alternative<TrackId>(cur->contents())) {
// New record is a leaf. // New record is a leaf.
break; break;

Loading…
Cancel
Save