Skip to content

Commit 5b041ab

Browse files
committed
A more efficient slice comparison implementation for T: !BytewiseEq
The previous implementation was not optimized properly by the compiler, which didn't leverage the fact that both length were equal.
1 parent 347452e commit 5b041ab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

library/core/src/slice/cmp.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ where
6060
return false;
6161
}
6262

63-
self.iter().zip(other.iter()).all(|(x, y)| x == y)
63+
// Implemented as explicit indexing rather
64+
// than zipped iterators for performance reasons.
65+
// See PR https://github.com/rust-lang/rust/pull/116846
66+
for idx in 0..self.len() {
67+
// bound checks are optimized away
68+
if self[idx] != other[idx] {
69+
return false;
70+
}
71+
}
72+
73+
true
6474
}
6575
}
6676

0 commit comments

Comments
 (0)