summaryrefslogtreecommitdiff
path: root/pkg/btrfs
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-02 20:46:04 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-02 20:46:04 -0600
commita1195c6b5dcd760aa939805727f92a2df306bfa5 (patch)
tree593cfa3724bc63ed1268591ad1b787c75add9c28 /pkg/btrfs
parente343bcf49febbf142aefb065fe1fa6b2ea17a247 (diff)
ls-trees: Crawl!
Diffstat (limited to 'pkg/btrfs')
-rw-r--r--pkg/btrfs/io3_btree.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/pkg/btrfs/io3_btree.go b/pkg/btrfs/io3_btree.go
index b4eb4cb..b5414ab 100644
--- a/pkg/btrfs/io3_btree.go
+++ b/pkg/btrfs/io3_btree.go
@@ -237,15 +237,16 @@ func (fs *FS) treeSearch(treeRoot btrfsvol.LogicalAddr, fn func(Key) int) (TreeP
// is returned.
//
// Implement this search as a binary search.
- items := node.Data.BodyLeaf
- for len(items) > 0 {
- midpoint := len(items) / 2
- direction := fn(items[midpoint].Head.Key)
+ beg := 0
+ end := len(node.Data.BodyLeaf) - 1
+ for beg < end {
+ midpoint := (beg + end) / 2
+ direction := fn(node.Data.BodyLeaf[midpoint].Head.Key)
switch {
case direction < 0:
- items = items[:midpoint]
+ end = midpoint
case direction > 0:
- items = items[midpoint+1:]
+ beg = midpoint + 1
case direction == 0:
path = append(path, TreePathElem{
ItemIdx: midpoint,