Skip to content

Commit

Permalink
perf: different PartialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 11, 2024
1 parent b00b2b8 commit 778bf2d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,30 @@ impl Hash for CachedPath {
}
}

fn partial_eq(a: &Path, b: &Path) -> bool {
let a = a.as_os_str().as_encoded_bytes();
let b = b.as_os_str().as_encoded_bytes();
let len = a.len();
if len != b.len() {
return false;
}
for i in (0..len).rev() {
let x = a[i];
let y = b[i];
if (x == b'/' || x == b'\\') && (y == b'/' || y == b'\\') {
continue;
}
if x == y {
continue;
}
return false;

Check warning on line 157 in src/cache.rs

View check run for this annotation

Codecov / codecov/patch

src/cache.rs#L156-L157

Added lines #L156 - L157 were not covered by tests
}
true
}

impl PartialEq for CachedPath {
fn eq(&self, other: &Self) -> bool {
self.0.path == other.0.path
partial_eq(self.path(), other.path())
}
}
impl Eq for CachedPath {}
Expand Down Expand Up @@ -404,7 +425,7 @@ impl Hash for dyn CacheKey + '_ {

impl PartialEq for dyn CacheKey + '_ {
fn eq(&self, other: &Self) -> bool {
self.tuple().1 == other.tuple().1
partial_eq(self.tuple().1, other.tuple().1)
}
}

Expand Down

0 comments on commit 778bf2d

Please sign in to comment.