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:
Yuya Nishihara 2023-01-20 13:58:43 +09:00
parent a29b19fa9d
commit a574987955

View file

@ -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;