diff --git a/lib/src/index.rs b/lib/src/index.rs index 34da05388..cc0180514 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -1334,28 +1334,26 @@ impl IndexSegment for ReadonlyIndex { fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes(); - match self.commit_id_byte_prefix_to_lookup_pos(&min_bytes_prefix) { - None => PrefixResolution::NoMatch, - Some(lookup_pos) => { - let mut first_match = None; - for i in lookup_pos..self.num_local_commits { - let entry = self.lookup_entry(i); - let id = entry.commit_id(); - if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) { - break; - } - if prefix.matches(&id) { - if first_match.is_some() { - return PrefixResolution::AmbiguousMatch; - } - first_match = Some(id) - } - } - match first_match { - None => PrefixResolution::NoMatch, - Some(id) => PrefixResolution::SingleMatch(id), - } + let lookup_pos = self + .commit_id_byte_prefix_to_lookup_pos(&min_bytes_prefix) + .unwrap_or(self.num_local_commits); + let mut first_match = None; + for i in lookup_pos..self.num_local_commits { + let entry = self.lookup_entry(i); + let id = entry.commit_id(); + if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) { + break; } + if prefix.matches(&id) { + if first_match.is_some() { + return PrefixResolution::AmbiguousMatch; + } + first_match = Some(id) + } + } + match first_match { + None => PrefixResolution::NoMatch, + Some(id) => PrefixResolution::SingleMatch(id), } } @@ -1440,26 +1438,19 @@ impl IndexSegment for MutableIndex { fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes(); - let mut potential_range = self + let potential_range = self .lookup .range((Bound::Included(&min_bytes_prefix), Bound::Unbounded)); let mut first_match = None; - loop { - match potential_range.next() { - None => { - break; - } - Some((id, _pos)) => { - if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) { - break; - } - if prefix.matches(id) { - if first_match.is_some() { - return PrefixResolution::AmbiguousMatch; - } - first_match = Some(id) - } + for (id, _pos) in potential_range { + if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) { + break; + } + if prefix.matches(id) { + if first_match.is_some() { + return PrefixResolution::AmbiguousMatch; } + first_match = Some(id) } } match first_match {