pub unsafe fn is_equal_raw(x: *const u8, y: *const u8, n: usize) -> bool
Expand description
Compare n
bytes at the given pointers for equality.
This returns true if and only if *x.add(i) == *y.add(i)
for all
0 <= i < n
.
§Inlining
This routine is marked inline(always)
. If you want to call this function
in a way that is not always inlined, you’ll need to wrap a call to it in
another function that is marked as inline(never)
or just inline
.
§Motivation
Why not use slice equality instead? Well, slice equality usually results in
a call out to the current platform’s libc
which might not be inlineable
or have other overhead. This routine isn’t guaranteed to be a win, but it
might be in some cases.
§Safety
- Both
x
andy
must be valid for reads of up ton
bytes. - Both
x
andy
must point to an initialized value. - Both
x
andy
must each point to an allocated object and must either be in bounds or at most one byte past the end of the allocated object.x
andy
do not need to point to the same allocated object, but they may. - Both
x
andy
must be derived from a pointer to their respective allocated objects. - The distance between
x
andx+n
must not overflowisize
. Similarly fory
andy+n
. - The distance being in bounds must not rely on “wrapping around” the address space.