Skip to content

Commit c1ea7bd

Browse files
committed
Prefix can be case-insensitive, delegate to its Hash impl instead of trying to hash the raw bytes
This should have 0 performance overhead on unix since Prefix is always None.
1 parent a6e0aa2 commit c1ea7bd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

library/std/src/path.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,14 @@ impl cmp::PartialEq for Path {
28922892
impl Hash for Path {
28932893
fn hash<H: Hasher>(&self, h: &mut H) {
28942894
let bytes = self.as_u8_slice();
2895+
let prefix_len = match parse_prefix(&self.inner) {
2896+
Some(prefix) => {
2897+
prefix.hash(h);
2898+
prefix.len()
2899+
}
2900+
None => 0,
2901+
};
2902+
let bytes = &bytes[prefix_len..];
28952903

28962904
let mut component_start = 0;
28972905
let mut bytes_hashed = 0;

library/std/src/sys/unix/path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub fn is_verbatim_sep(b: u8) -> bool {
1111
b == b'/'
1212
}
1313

14+
#[inline]
1415
pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> {
1516
None
1617
}

0 commit comments

Comments
 (0)