Skip to content

Commit

Permalink
Prefix can be case-insensitive, delegate to its Hash impl instead o…
Browse files Browse the repository at this point in the history
…f trying to hash the raw bytes

This should have 0 performance overhead on unix since Prefix is always None.
  • Loading branch information
the8472 committed Nov 11, 2021
1 parent a6e0aa2 commit c1ea7bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2892,6 +2892,14 @@ impl cmp::PartialEq for Path {
impl Hash for Path {
fn hash<H: Hasher>(&self, h: &mut H) {
let bytes = self.as_u8_slice();
let prefix_len = match parse_prefix(&self.inner) {
Some(prefix) => {
prefix.hash(h);
prefix.len()
}
None => 0,
};
let bytes = &bytes[prefix_len..];

let mut component_start = 0;
let mut bytes_hashed = 0;
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unix/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn is_verbatim_sep(b: u8) -> bool {
b == b'/'
}

#[inline]
pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> {
None
}
Expand Down

0 comments on commit c1ea7bd

Please sign in to comment.