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.
This commit is contained in:
Arthur Carcano 2023-07-13 12:46:14 +02:00
parent 347452e7e3
commit 5b041abc8c

View File

@ -60,7 +60,17 @@ where
return false;
}
self.iter().zip(other.iter()).all(|(x, y)| x == y)
// Implemented as explicit indexing rather
// than zipped iterators for performance reasons.
// See PR https://github.com/rust-lang/rust/pull/116846
for idx in 0..self.len() {
// bound checks are optimized away
if self[idx] != other[idx] {
return false;
}
}
true
}
}