libroot/string: Compare size_ts in memcmp(), not uint32_ts.

Should get a small bit more of performance on 64-bit architectures.
This commit is contained in:
Augustin Cavalier
2025-03-03 14:16:05 -05:00
parent 333274ddfb
commit 0c76e02c58
+9 -9
View File
@@ -14,17 +14,17 @@ memcmp(const void *_a, const void *_b, size_t count)
const unsigned char *a = (const unsigned char *)_a; const unsigned char *a = (const unsigned char *)_a;
const unsigned char *b = (const unsigned char *)_b; const unsigned char *b = (const unsigned char *)_b;
if ((((addr_t)a) & 3) == 0 && (((addr_t)b) & 3) == 0) { if ((((addr_t)a) & (sizeof(size_t) - 1)) == 0 && (((addr_t)b) & (sizeof(size_t) - 1)) == 0) {
uint32_t *a32 = (uint32_t *)a; size_t *asz = (size_t *)a;
uint32_t *b32 = (uint32_t *)b; size_t *bsz = (size_t *)b;
while (count >= 4 && *a32 == *b32) { while (count >= sizeof(size_t) && *asz == *bsz) {
a32++; asz++;
b32++; bsz++;
count -= 4; count -= sizeof(size_t);
} }
a = (const unsigned char *)a32; a = (const unsigned char *)asz;
b = (const unsigned char *)b32; b = (const unsigned char *)bsz;
} }
while (count-- > 0) { while (count-- > 0) {