diff options
| author | Trevor Gross <tmgross@umich.edu> | 2025-07-31 19:56:57 +0000 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2025-07-31 22:47:24 +0000 |
| commit | 8d0b92acbff06a46519e012c6a171d0554e0d8ef (patch) | |
| tree | 2f6fba97198ecf2c2185a8df7a8c0dba32532df4 /library/std | |
| parent | e5e79f8bd428d0b8d26e8240d718b134ef297459 (diff) | |
| download | rust-8d0b92acbff06a46519e012c6a171d0554e0d8ef.tar.gz rust-8d0b92acbff06a46519e012c6a171d0554e0d8ef.zip | |
uefi: Use slice equality rather than `memcmp`
`compiler_builtins` shouldn't be called directly. Change the `PartialEq` implementation for `DevicePathNode` to use slice equality instead, which will call `memcmp`/`bcmp` via the intrinsic.
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/sys/pal/uefi/helpers.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/library/std/src/sys/pal/uefi/helpers.rs b/library/std/src/sys/pal/uefi/helpers.rs index 271dc4d11de..b50574de937 100644 --- a/library/std/src/sys/pal/uefi/helpers.rs +++ b/library/std/src/sys/pal/uefi/helpers.rs @@ -444,17 +444,17 @@ impl<'a> DevicePathNode<'a> { impl<'a> PartialEq for DevicePathNode<'a> { fn eq(&self, other: &Self) -> bool { - let self_len = self.length(); - let other_len = other.length(); - - self_len == other_len - && unsafe { - compiler_builtins::mem::memcmp( - self.protocol.as_ptr().cast(), - other.protocol.as_ptr().cast(), - usize::from(self_len), - ) == 0 - } + // Compare as a single buffer rather than by field since it optimizes better. + // + // SAFETY: `Protocol` is followed by a buffer of `length - sizeof::<Protocol>()`. `Protocol` + // has no padding so it is sound to interpret as a slice. + unsafe { + let s1 = + slice::from_raw_parts(self.protocol.as_ptr().cast::<u8>(), self.length().into()); + let s2 = + slice::from_raw_parts(other.protocol.as_ptr().cast::<u8>(), other.length().into()); + s1 == s2 + } } } |
