diff options
| author | bors <bors@rust-lang.org> | 2021-06-16 15:18:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-16 15:18:19 +0000 |
| commit | 9fef8d91b4a6c5bfe07c025c434f2d623ad83337 (patch) | |
| tree | 68ebf8f862d1c29d2ad3cbc1cd6a0e92c722e38e | |
| parent | 8daad743c4bb941536860b4df20111cb71b8c777 (diff) | |
| parent | 53d71c181e53be51a1e122146c504e758f304c38 (diff) | |
| download | rust-9fef8d91b4a6c5bfe07c025c434f2d623ad83337.tar.gz rust-9fef8d91b4a6c5bfe07c025c434f2d623ad83337.zip | |
Auto merge of #86179 - the8472:revere-path-cmp, r=kennytm
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) ```
| -rw-r--r-- | library/std/src/path.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index ede147aca12..6ccf4c9656e 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -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()) } } |
