We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d8899c5 commit be64090Copy full SHA for be64090
library/core/src/slice/cmp.rs
@@ -70,7 +70,24 @@ where
70
return false;
71
}
72
73
- self.iter().zip(other.iter()).all(|(x, y)| x == y)
+ let mut i = self.len();
74
+ let mut ptr_self = self.as_ptr();
75
+ let mut ptr_other = other.as_ptr();
76
+ // SAFETY:
77
+ // This is sound because:
78
+ // - self.len == other.len
79
+ // - self.len <= isize::MAX
80
+ // so the two pointers will not overflow,
81
+ // will remain in bounds of the slice,
82
+ // and dereferencing them is sound.
83
+ unsafe {
84
+ while (i > 0) && (*ptr_self == *ptr_other) {
85
+ i -= 1;
86
+ ptr_self = ptr_self.add(1);
87
+ ptr_other = ptr_other.add(1);
88
+ }
89
90
+ i == 0
91
92
93
0 commit comments