diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-06-23 00:33:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-23 00:33:54 -0700 |
| commit | ae38698e7fca180d612dc11be12023076e23236c (patch) | |
| tree | 0d6facabc6acf33196c2d87b81ff79035deffc32 /src/libcore/slice | |
| parent | 903823c59bcb9890df2a6fadcf7aa22f74eed67f (diff) | |
| parent | e465b227d15fec8f16863ba8e77191ceb5c8670b (diff) | |
| download | rust-ae38698e7fca180d612dc11be12023076e23236c.tar.gz rust-ae38698e7fca180d612dc11be12023076e23236c.zip | |
Rollup merge of #73398 - oli-obk:const_raw_ptr_cmp, r=varkor,RalfJung,nagisa
A way forward for pointer equality in const eval r? @varkor on the first commit and @RalfJung on the second commit cc #53020
Diffstat (limited to 'src/libcore/slice')
| -rw-r--r-- | src/libcore/slice/mod.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 21ba2b5abcf..c69aafe687c 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -5956,10 +5956,18 @@ where return false; } + #[cfg(bootstrap)] if self.as_ptr() == other.as_ptr() { return true; } + // While performance would suffer if `guaranteed_eq` just returned `false` + // for all arguments, correctness and return value of this function are not affected. + #[cfg(not(bootstrap))] + if self.as_ptr().guaranteed_eq(other.as_ptr()) { + return true; + } + self.iter().zip(other.iter()).all(|(x, y)| x == y) } } @@ -5973,9 +5981,18 @@ where if self.len() != other.len() { return false; } + + #[cfg(bootstrap)] if self.as_ptr() == other.as_ptr() { return true; } + + // While performance would suffer if `guaranteed_eq` just returned `false` + // for all arguments, correctness and return value of this function are not affected. + #[cfg(not(bootstrap))] + if self.as_ptr().guaranteed_eq(other.as_ptr()) { + return true; + } unsafe { let size = mem::size_of_val(self); memcmp(self.as_ptr() as *const u8, other.as_ptr() as *const u8, size) == 0 |
