Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
tgross35 committed Jul 31, 2025
commit 8d0b92acbff06a46519e012c6a171d0554e0d8ef
22 changes: 11 additions & 11 deletions library/std/src/sys/pal/uefi/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down