about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-06-01 12:57:41 +0530
committerManish Goregaokar <manishsmail@gmail.com>2016-06-01 12:57:41 +0530
commit7694e18d4351b046ff8201af178bb82f9cbec34a (patch)
treea2a23c4ab2aced3c4f43a6c2a5d082a7cb17fc2d
parent4721f3a543ef00952d5ce39b64dbfe1ce57667fd (diff)
parent6af17e69ff5a69892aff4d82b293de2ec7f5050a (diff)
downloadrust-7694e18d4351b046ff8201af178bb82f9cbec34a.tar.gz
rust-7694e18d4351b046ff8201af178bb82f9cbec34a.zip
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.
-rw-r--r--src/libcore/slice.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index 72d32607638..b6ae6fde1e3 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -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,