We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 347452e commit 0cc5c97Copy full SHA for 0cc5c97
library/core/src/slice/cmp.rs
@@ -60,7 +60,24 @@ where
60
return false;
61
}
62
63
- self.iter().zip(other.iter()).all(|(x, y)| x == y)
+ let mut i = self.len();
64
+ let mut ptr_self = self.as_ptr();
65
+ let mut ptr_other = other.as_ptr();
66
+ // SAFETY:
67
+ // This is sound because:
68
+ // - self.len == other.len
69
+ // - self.len <= isize::MAX
70
+ // so the two pointers will not overflow,
71
+ // will remain in bounds of the slice,
72
+ // and dereferencing them is sound.
73
+ unsafe {
74
+ while (i > 0) && (*ptr_self == *ptr_other) {
75
+ i -= 1;
76
+ ptr_self = ptr_self.add(1);
77
+ ptr_other = ptr_other.add(1);
78
+ }
79
80
+ i == 0
81
82
83
0 commit comments