@@ -979,6 +979,25 @@ impl FusedIterator for Components<'_> {}
979
979
impl < ' a > cmp:: PartialEq for Components < ' a > {
980
980
#[ inline]
981
981
fn eq ( & self , other : & Components < ' a > ) -> bool {
982
+ let Components { path : _, front : _, back : _, has_physical_root : _, prefix : _ } = self ;
983
+
984
+ // Fast path for exact matches, e.g. for hashmap lookups.
985
+ // Don't explicitly compare the prefix or has_physical_root fields since they'll
986
+ // either be covered by the `path` buffer or are only relevant for `prefix_verbatim()`.
987
+ if self . path . len ( ) == other. path . len ( )
988
+ && self . front == other. front
989
+ && self . back == State :: Body
990
+ && other. back == State :: Body
991
+ && self . prefix_verbatim ( ) == other. prefix_verbatim ( )
992
+ {
993
+ // possible future improvement: this could bail out earlier if there were a
994
+ // reverse memcmp/bcmp comparing back to front
995
+ if self . path == other. path {
996
+ return true ;
997
+ }
998
+ }
999
+
1000
+ // compare back to front since absolute paths often share long prefixes
982
1001
Iterator :: eq ( self . clone ( ) . rev ( ) , other. clone ( ) . rev ( ) )
983
1002
}
984
1003
}
@@ -1013,7 +1032,7 @@ fn compare_components(mut left: Components<'_>, mut right: Components<'_>) -> cm
1013
1032
// The fast path isn't taken for paths with a PrefixComponent to avoid backtracking into
1014
1033
// the middle of one
1015
1034
if left. prefix . is_none ( ) && right. prefix . is_none ( ) && left. front == right. front {
1016
- // this might benefit from a [u8]::first_mismatch simd implementation, if it existed
1035
+ // possible future improvement: a [u8]::first_mismatch simd implementation
1017
1036
let first_difference =
1018
1037
match left. path . iter ( ) . zip ( right. path . iter ( ) ) . position ( |( & a, & b) | a != b) {
1019
1038
None if left. path . len ( ) == right. path . len ( ) => return cmp:: Ordering :: Equal ,
0 commit comments