Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leveldb/memdb: avoid repeated comparisons #384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion leveldb/memdb/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,23 @@ func (p *DB) randHeight() (h int) {
func (p *DB) findGE(key []byte, prev bool) (int, bool) {
node := 0
h := p.maxHeight - 1
visited := 0
for {
next := p.nodeData[node+nNext+h]
cmp := 1
if next != 0 {
if next != 0 && next != visited {
o := p.nodeData[next]
cmp = p.cmp.Compare(p.kvData[o:o+p.nodeData[next+nKey]], key)
}
if cmp < 0 {
// Keep searching in this list
node = next
} else {
if next != 0 && cmp != 0 {
// If we go down further, we can skip this element if we
// encounter it on a lower level.
visited = next
}
if prev {
p.prevNode[h] = node
} else if cmp == 0 {
Expand Down