Skip to content

Commit 926e93b

Browse files
committed
arenaskl: inline findSpliceForLevel in seekForBaseSplice
Manually inline findSpliceForLevel in the arenaskl.Iterator's seeking function, seekForBaseSplice.
1 parent 7bf6000 commit 926e93b

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

internal/arenaskl/iterator.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,41 @@ func (it *Iterator) decodeKey() {
261261

262262
func (it *Iterator) seekForBaseSplice(key []byte) (prev, next *node, found bool) {
263263
ikey := base.MakeSearchKey(key)
264-
level := int(it.list.Height() - 1)
265264

266265
prev = it.list.head
267-
for {
268-
prev, next, found = it.list.findSpliceForLevel(ikey, level, prev)
266+
for level := int(it.list.Height() - 1); level >= 0; level-- {
267+
268+
// Search this level for the key.
269+
for {
270+
// Assume prev.key < key.
271+
next = it.list.getNext(prev, level)
272+
if next == it.list.tail {
273+
// Tail node, so done.
274+
break
275+
}
276+
277+
offset, size := next.keyOffset, next.keySize
278+
nextKey := it.list.arena.buf[offset : offset+size]
279+
cmp := it.list.cmp(ikey.UserKey, nextKey)
280+
if cmp < 0 {
281+
// We are done for this level, since prev.key < key < next.key.
282+
break
283+
}
284+
if cmp == 0 {
285+
// User-key equality.
286+
if ikey.Trailer == next.keyTrailer {
287+
// Internal key equality.
288+
found = true
289+
break
290+
}
291+
if ikey.Trailer > next.keyTrailer {
292+
// We are done for this level, since prev.key < key < next.key.
293+
break
294+
}
295+
}
296+
// Keep moving right on this level.
297+
prev = next
298+
}
269299

270300
if found {
271301
if level != 0 {
@@ -275,13 +305,7 @@ func (it *Iterator) seekForBaseSplice(key []byte) (prev, next *node, found bool)
275305
}
276306
break
277307
}
278-
279-
if level == 0 {
280-
break
281-
}
282-
283-
level--
284308
}
285309

286-
return
310+
return prev, next, found
287311
}

0 commit comments

Comments
 (0)