mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-30 08:05:05 +00:00
index: simplify segment_resolve_prefix() loop to make both impls look close
This commit is contained in:
parent
5d675f13a2
commit
b4c837fd4a
1 changed files with 28 additions and 37 deletions
|
@ -1334,9 +1334,9 @@ impl IndexSegment for ReadonlyIndex {
|
||||||
|
|
||||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
||||||
match self.commit_id_byte_prefix_to_lookup_pos(&min_bytes_prefix) {
|
let lookup_pos = self
|
||||||
None => PrefixResolution::NoMatch,
|
.commit_id_byte_prefix_to_lookup_pos(&min_bytes_prefix)
|
||||||
Some(lookup_pos) => {
|
.unwrap_or(self.num_local_commits);
|
||||||
let mut first_match = None;
|
let mut first_match = None;
|
||||||
for i in lookup_pos..self.num_local_commits {
|
for i in lookup_pos..self.num_local_commits {
|
||||||
let entry = self.lookup_entry(i);
|
let entry = self.lookup_entry(i);
|
||||||
|
@ -1356,8 +1356,6 @@ impl IndexSegment for ReadonlyIndex {
|
||||||
Some(id) => PrefixResolution::SingleMatch(id),
|
Some(id) => PrefixResolution::SingleMatch(id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn segment_generation_number(&self, local_pos: u32) -> u32 {
|
fn segment_generation_number(&self, local_pos: u32) -> u32 {
|
||||||
self.graph_entry(local_pos).generation_number()
|
self.graph_entry(local_pos).generation_number()
|
||||||
|
@ -1440,16 +1438,11 @@ impl IndexSegment for MutableIndex {
|
||||||
|
|
||||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
||||||
let mut potential_range = self
|
let potential_range = self
|
||||||
.lookup
|
.lookup
|
||||||
.range((Bound::Included(&min_bytes_prefix), Bound::Unbounded));
|
.range((Bound::Included(&min_bytes_prefix), Bound::Unbounded));
|
||||||
let mut first_match = None;
|
let mut first_match = None;
|
||||||
loop {
|
for (id, _pos) in potential_range {
|
||||||
match potential_range.next() {
|
|
||||||
None => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Some((id, _pos)) => {
|
|
||||||
if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) {
|
if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1460,8 +1453,6 @@ impl IndexSegment for MutableIndex {
|
||||||
first_match = Some(id)
|
first_match = Some(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
match first_match {
|
match first_match {
|
||||||
None => PrefixResolution::NoMatch,
|
None => PrefixResolution::NoMatch,
|
||||||
Some(id) => PrefixResolution::SingleMatch(id.clone()),
|
Some(id) => PrefixResolution::SingleMatch(id.clone()),
|
||||||
|
|
Loading…
Reference in a new issue