Rollup merge of #33892 - seanmonstar:slice-eq-ptr, r=alexcrichton
core: check pointer equality when comparing byte slices If pointer address and length are the same, it should be the same slice. In experiments, I've seen that this doesn't happen as often in debug builds, but release builds seem to optimize to using a single pointer more often.
This commit is contained in:
commit
7694e18d43
1 changed files with 3 additions and 0 deletions
|
|
@ -1830,6 +1830,9 @@ impl<A> SlicePartialEq<A> for [A]
|
|||
if self.len() != other.len() {
|
||||
return false;
|
||||
}
|
||||
if self.as_ptr() == other.as_ptr() {
|
||||
return true;
|
||||
}
|
||||
unsafe {
|
||||
let size = mem::size_of_val(self);
|
||||
memcmp(self.as_ptr() as *const u8,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue