We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2624523 commit 9d3905fCopy full SHA for 9d3905f
library/core/src/slice/cmp.rs
@@ -60,7 +60,22 @@ where
60
return false;
61
}
62
63
- self.iter().zip(other.iter()).all(|(x, y)| x == y)
+ let (chunks_a, residual_a) = self.as_chunks::<4>();
64
+ let (chunks_b, residual_b) = other.as_chunks::<4>();
65
+
66
+ // check the residual first to bail out fast if there's a mismatch and comparisons
67
+ // happen to be expensive
68
+ let mut result = residual_a.into_iter().zip(residual_b).all(|(a, b)| a == b);
69
70
+ // iter.all short-circuits which means the backend can't unroll the loop due to early exits.
71
+ // So we unroll it manually.
72
+ result = result
73
+ && chunks_a
74
+ .iter()
75
+ .zip(chunks_b.iter())
76
+ .all(|(a, b)| (a[0] == b[0]) & (a[1] == b[1]) & (a[2] == b[2]) & (a[3] == b[3]));
77
78
+ result
79
80
81
0 commit comments