Skip to content

Commit

Permalink
Auto merge of rust-lang#86179 - the8472:revere-path-cmp, r=kennytm
Browse files Browse the repository at this point in the history
optimize Eq implementation for paths

Filesystems generally have a tree-ish structure which means paths are more likely to share a prefix than a suffix. Absolute paths are especially prone to share long prefixes.

quick benchmark consisting of a search through through a vec containing the absolute paths of all (1850) files in `compiler/`:

```
# old
test path::tests::bench_path_cmp                                  ... bench:     227,407 ns/iter (+/- 2,162)

# new
test path::tests::bench_path_cmp                                  ... bench:      64,976 ns/iter (+/- 1,142)
```
  • Loading branch information
bors committed Jun 16, 2021
2 parents 8daad74 + 53d71c1 commit 9fef8d9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ impl FusedIterator for Components<'_> {}
impl<'a> cmp::PartialEq for Components<'a> {
#[inline]
fn eq(&self, other: &Components<'a>) -> bool {
Iterator::eq(self.clone(), other.clone())
Iterator::eq(self.clone().rev(), other.clone().rev())
}
}

Expand Down

0 comments on commit 9fef8d9

Please sign in to comment.