Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/trie/common/src/prefix_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ impl PrefixSet {
return true
}

// Early bounds check to help compiler eliminate redundant checks in the while loop
// If index is out of bounds, reset to 0 to avoid unnecessary backward scanning
if self.index >= self.keys.len() {
self.index = 0;
}

while self.index > 0 && &self.keys[self.index] > prefix {
self.index -= 1;
}
Expand Down