mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-17 17:55:29 +00:00
index: remove redundant slicing from commit_id-prefix search function
If commit_id[..prefix_len] < prefix, commit_id < prefix is obviously true. If commit_id[..prefix_len] == prefix, commit_id < prefix returns false. So slicing isn't needed. This makes commit_id_byte_prefix_to_pos() basically the same as segment_commit_id_to_pos(), and these two functions can be merged.
This commit is contained in:
parent
a29b19fa9d
commit
a574987955
1 changed files with 2 additions and 5 deletions
|
@ -1621,18 +1621,15 @@ impl ReadonlyIndex {
|
|||
}
|
||||
let mut low = 0;
|
||||
let mut high = self.num_local_commits - 1;
|
||||
let prefix_len = prefix.as_bytes().len();
|
||||
|
||||
// binary search for the commit id
|
||||
loop {
|
||||
let mid = (low + high) / 2;
|
||||
let entry = self.lookup_entry(mid);
|
||||
let entry_commit_id = entry.commit_id();
|
||||
let entry_prefix = &entry_commit_id.as_bytes()[0..prefix_len];
|
||||
if high == low {
|
||||
return Some(IndexPosition(mid));
|
||||
}
|
||||
if entry_prefix < prefix.as_bytes() {
|
||||
let entry = self.lookup_entry(mid);
|
||||
if entry.commit_id().as_bytes() < prefix.as_bytes() {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid;
|
||||
|
|
Loading…
Reference in a new issue