Skip to content

Consider improving memcmp #257

@ncruces

Description

@ncruces

Something like:

int memcmp(const void *vl, const void *vr, size_t n) {
  const uint64_t *wl = (const uint64_t *)vl;
  const uint64_t *wr = (const uint64_t *)vr;

  if (n >= 4 * sizeof(uint64_t)) {
    do {
      if (*wl != *wr) break;
      n -= sizeof(uint64_t);
      wl++;
      wr++;
    } while (n >= sizeof(uint64_t));
  }

  const char *b1 = (const char *)wl;
  const char *b2 = (const char *)wr;

  while (n--) {
    if (*b1 != *b2) return *b1 - *b2;
    b1++;
    b2++;
  }

  return 0;
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions