diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2020-02-02 16:45:20 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2020-04-24 14:13:14 -0400 |
commit | 20223b1918fc1cfdb799b855bf717f368c3412d9 (patch) | |
tree | 8191aba6922063ebd0377364b47de50cddccf656 | |
parent | 653b4439921c1a66523fa9fbfbb3c9498abbc71f (diff) |
bcachefs: binary search improvementextent-overwrite
-rw-r--r-- | fs/bcachefs/bset.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/bcachefs/bset.c b/fs/bcachefs/bset.c index 6360b2e8cf73..4c46e72749b0 100644 --- a/fs/bcachefs/bset.c +++ b/fs/bcachefs/bset.c @@ -1241,13 +1241,17 @@ static struct bkey_packed *bset_search_write_set(const struct btree *b, { unsigned l = 0, r = t->size; - while (l + 1 != r) { - unsigned m = (l + r) >> 1; + BUG_ON(!t->size); - if (bkey_cmp(rw_aux_tree(b, t)[m].k, *search) < 0) + while (l < r) { + unsigned m = l + ((r - l) >> 1); + + if (bkey_cmp(*search, rw_aux_tree(b, t)[m].k) <= 0) + r = m; + else if (l < m) l = m; else - r = m; + break; } return rw_aux_to_bkey(b, t, l); |