Skip to content

Commit

Permalink
Minor code stlye change in the Facet::is_prefix_of. (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton authored Aug 19, 2022
1 parent 27400c9 commit e25ab5d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/schema/facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@ impl Facet {

/// Returns `true` if other is a subfacet of `self`.
pub fn is_prefix_of(&self, other: &Facet) -> bool {
// Root is a prefix of every other path.
// This is not just an optimisation. It is necessary for correctness.
if self.is_root() {
return true;
}
let self_str = self.encoded_str();
let other_str = other.encoded_str();
self_str.len() < other_str.len()
&& other_str.starts_with(self_str)
&& (self_str.len() == 0 || other_str.as_bytes()[self_str.len()] == FACET_SEP_BYTE)
other_str.starts_with(self_str) && other_str.as_bytes()[self_str.len()] == FACET_SEP_BYTE
}

/// Extract path from the `Facet`.
Expand Down

0 comments on commit e25ab5d

Please sign in to comment.