mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
index: remove allocation from bisection loop of commit_id prefix search
This wouldn't actually matter since the depth of binary search is O(log(N)), but I feel it's better to avoid allocation in comparison loop.
This commit is contained in:
parent
2b7021664d
commit
763a8cc0f1
1 changed files with 7 additions and 2 deletions
|
@ -203,7 +203,12 @@ impl CommitLookupEntry<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_id(&self) -> CommitId {
|
fn commit_id(&self) -> CommitId {
|
||||||
CommitId::from_bytes(&self.data[0..self.hash_length])
|
CommitId::from_bytes(self.commit_id_bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
// might be better to add borrowed version of CommitId
|
||||||
|
fn commit_id_bytes(&self) -> &[u8] {
|
||||||
|
&self.data[0..self.hash_length]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pos(&self) -> IndexPosition {
|
fn pos(&self) -> IndexPosition {
|
||||||
|
@ -1611,7 +1616,7 @@ impl ReadonlyIndex {
|
||||||
return Some(mid);
|
return Some(mid);
|
||||||
}
|
}
|
||||||
let entry = self.lookup_entry(mid);
|
let entry = self.lookup_entry(mid);
|
||||||
if entry.commit_id().as_bytes() < prefix.as_bytes() {
|
if entry.commit_id_bytes() < prefix.as_bytes() {
|
||||||
low = mid + 1;
|
low = mid + 1;
|
||||||
} else {
|
} else {
|
||||||
high = mid;
|
high = mid;
|
||||||
|
|
Loading…
Reference in a new issue