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.
This commit is contained in:
Trevor Gross
2025-07-31 19:56:57 +00:00
parent e5e79f8bd4
commit 8d0b92acbf

View File

@@ -444,17 +444,17 @@ impl<'a> DevicePathNode<'a> {
impl<'a> PartialEq for DevicePathNode<'a> { impl<'a> PartialEq for DevicePathNode<'a> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
let self_len = self.length(); // Compare as a single buffer rather than by field since it optimizes better.
let other_len = other.length(); //
// SAFETY: `Protocol` is followed by a buffer of `length - sizeof::<Protocol>()`. `Protocol`
self_len == other_len // has no padding so it is sound to interpret as a slice.
&& unsafe { unsafe {
compiler_builtins::mem::memcmp( let s1 =
self.protocol.as_ptr().cast(), slice::from_raw_parts(self.protocol.as_ptr().cast::<u8>(), self.length().into());
other.protocol.as_ptr().cast(), let s2 =
usize::from(self_len), slice::from_raw_parts(other.protocol.as_ptr().cast::<u8>(), other.length().into());
) == 0 s1 == s2
} }
} }
} }