Skip to content

Commit a70613b

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 a70613b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/core/src/slice/cmp.rs

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

63-
self.iter().zip(other.iter()).all(|(x, y)| x == y)
63+
for idx in 0..self.len() {
64+
// bound checks are optimized away
65+
if self[idx] != other[idx] {
66+
return false;
67+
}
68+
}
69+
70+
true
6471
}
6572
}
6673

0 commit comments

Comments
 (0)