FOLLY_ALWAYS_INLINE bool bytesEqual()

in cachelib/common/BytesEqual.h [54:91]


FOLLY_ALWAYS_INLINE bool bytesEqual(const void* a_,
                                    const void* b_,
                                    size_t len) {
  const char* a = (const char*)a_;
  const char* b = (const char*)b_;

  if (UNLIKELY(len >= 1024)) {
    return memcmp(a_, b_, len) == 0;
  }

  while (len >= 8 && eq<uint64_t>(a, b)) {
    a += 8;
    b += 8;
    len -= 8;
  }

  if (len >= 8) {
    return false;
  }

  if (len >= 4 && eq<uint32_t>(a, b)) {
    a += 4;
    b += 4;
    len -= 4;
  }

  if (len >= 4) {
    return false;
  }

  if (len >= 2 && eq<uint16_t>(a, b)) {
    a += 2;
    b += 2;
    len -= 2;
  }

  return (len == 1 && *a == *b) || len == 0;
}