Function aho_corasick::packed::pattern::is_equal_raw

source ·
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 and y must be valid for reads of up to n bytes.
  • Both x and y must point to an initialized value.
  • Both x and y 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 and y do not need to point to the same allocated object, but they may.
  • Both x and y must be derived from a pointer to their respective allocated objects.
  • The distance between x and x+n must not overflow isize. Similarly for y and y+n.
  • The distance being in bounds must not rely on “wrapping around” the address space.