From 0ba1ef0bab39c2ecca77dbbee7d107f7f961ae39 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 18 Feb 2016 19:18:08 +1300 Subject: [PATCH] Fold BtreeCursor::prev() into find_entry_lt() This is the only place it is used, and we can make several simplifications based on knowing the context it's called in. --- xapian-core/backends/glass/glass_cursor.cc | 68 +++++++++++------------------- xapian-core/backends/glass/glass_cursor.h | 11 +---- 2 files changed, 25 insertions(+), 54 deletions(-) diff --git a/xapian-core/backends/glass/glass_cursor.cc b/xapian-core/backends/glass/glass_cursor.cc index ffa4a8bf5..77e38d45c 100644 --- a/xapian-core/backends/glass/glass_cursor.cc +++ b/xapian-core/backends/glass/glass_cursor.cc @@ -100,50 +100,6 @@ GlassCursor::~GlassCursor() } bool -GlassCursor::prev() -{ - LOGCALL(DB, bool, "GlassCursor::prev", NO_ARGS); - Assert(!is_after_end); - if (B->cursor_version != version || !is_positioned) { - // Either the cursor needs rebuilding (in which case find_entry() will - // call rebuild() and then reposition the cursor), or we've read the - // last key and tag, and we're now not positioned (in which case we - // seek to the current key, and then it's as if we read the key but not - // the tag). - if (!find_entry(current_key)) { - // Exact entry was no longer there after rebuild(), and we've - // automatically ended up on the entry before it. - RETURN(true); - } - } else if (tag_status != UNREAD) { - while (true) { - if (! B->prev(C, 0)) { - is_positioned = false; - RETURN(false); - } - if (LeafItem(C[0].get_p(), C[0].c).component_of() == 1) { - break; - } - } - } - - while (true) { - if (! B->prev(C, 0)) { - is_positioned = false; - RETURN(false); - } - if (LeafItem(C[0].get_p(), C[0].c).component_of() == 1) { - break; - } - } - get_key(¤t_key); - tag_status = UNREAD; - - LOGLINE(DB, "Moved to entry: key=" << hex_display_encode(current_key)); - RETURN(true); -} - -bool GlassCursor::next() { LOGCALL(DB, bool, "GlassCursor::next", NO_ARGS); @@ -228,6 +184,30 @@ done: RETURN(found); } +void +GlassCursor::find_entry_lt(const string &key) +{ + LOGCALL_VOID(DB, "GlassCursor::find_entry_lt", key); + if (!find_entry(key)) { + // The entry wasn't found, so find_entry() left us on the entry before + // the one we asked for and we're done. + return; + } + + Assert(!is_after_end); + Assert(is_positioned); + + do { + if (! B->prev(C, 0)) { + is_positioned = false; + return; + } + } while (LeafItem(C[0].get_p(), C[0].c).component_of() != 1); + get_key(¤t_key); + + LOGLINE(DB, "Found entry: key=" << hex_display_encode(current_key)); +} + bool GlassCursor::find_exact(const string &key) { diff --git a/xapian-core/backends/glass/glass_cursor.h b/xapian-core/backends/glass/glass_cursor.h index e7ed3c855..89a1c11a3 100644 --- a/xapian-core/backends/glass/glass_cursor.h +++ b/xapian-core/backends/glass/glass_cursor.h @@ -273,13 +273,6 @@ class GlassCursor { */ bool next(); - /** Move to the previous key. - * - * This is like GlassCursor::next, but BC is taken to the previous - * rather than next item. - */ - bool prev(); - /** Position the cursor on the highest entry with key <= @a key. * * If the exact key is found in the table, the cursor will be @@ -315,9 +308,7 @@ class GlassCursor { bool find_exact(const string &key); /// Position the cursor on the highest entry with key < @a key. - void find_entry_lt(const string &key) { - if (find_entry(key)) prev(); - } + void find_entry_lt(const string &key); /** Position the cursor on the lowest entry with key >= @a key. * -- 2.11.4.GIT