mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
node iterator seek: compare paths without terminator byte
This commit is contained in:
parent
e206d3f897
commit
7d25dfe6f8
1 changed files with 10 additions and 1 deletions
|
|
@ -311,7 +311,7 @@ func (it *nodeIterator) seek(prefix []byte) error {
|
|||
return errIteratorEnd
|
||||
} else if err != nil {
|
||||
return seekError{prefix, err}
|
||||
} else if bytes.Compare(path, key) >= 0 {
|
||||
} else if reachedPath(path, key) {
|
||||
return nil
|
||||
}
|
||||
it.push(state, parentIndex, path)
|
||||
|
|
@ -554,6 +554,15 @@ func (it *nodeIterator) pop() {
|
|||
it.putInPool(last)
|
||||
}
|
||||
|
||||
// reachedPath normalizes a path by truncating a terminator if present, and returns true if it is
|
||||
// greater than or equal to the target.
|
||||
func reachedPath(path, target []byte) bool {
|
||||
if hasTerm(path) {
|
||||
path = path[:len(path)-1]
|
||||
}
|
||||
return bytes.Compare(path, target) >= 0
|
||||
}
|
||||
|
||||
func compareNodes(a, b NodeIterator) int {
|
||||
if cmp := bytes.Compare(a.Path(), b.Path()); cmp != 0 {
|
||||
return cmp
|
||||
|
|
|
|||
Loading…
Reference in a new issue