diff options
| author | The8472 <git@infinite-source.de> | 2021-11-11 21:42:59 +0100 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2021-11-11 21:44:12 +0100 |
| commit | c1ea7bdc87a07c733769fd6adaa16818d692df24 (patch) | |
| tree | a410466fb44e116fef9ee1e5e83c1dcfae64c98b /library/std/src | |
| parent | a6e0aa20d90ee9173a6b901c641a8d48abbd82db (diff) | |
| download | rust-c1ea7bdc87a07c733769fd6adaa16818d692df24.tar.gz rust-c1ea7bdc87a07c733769fd6adaa16818d692df24.zip | |
`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.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/path.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys/unix/path.rs | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 7e1135365cd..cf2cd5adc48 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -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; diff --git a/library/std/src/sys/unix/path.rs b/library/std/src/sys/unix/path.rs index 840a7ae0426..717add9ec48 100644 --- a/library/std/src/sys/unix/path.rs +++ b/library/std/src/sys/unix/path.rs @@ -11,6 +11,7 @@ pub fn is_verbatim_sep(b: u8) -> bool { b == b'/' } +#[inline] pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> { None } |
