diff --git a/src/system/libroot/posix/string/memcmp.c b/src/system/libroot/posix/string/memcmp.c index f5034c0beb..c11be1b5ef 100644 --- a/src/system/libroot/posix/string/memcmp.c +++ b/src/system/libroot/posix/string/memcmp.c @@ -4,6 +4,7 @@ */ +#include #include @@ -13,6 +14,19 @@ memcmp(const void *_a, const void *_b, size_t count) const unsigned char *a = (const unsigned char *)_a; const unsigned char *b = (const unsigned char *)_b; + if ((((addr_t)a) & 3) == 0 && (((addr_t)b) & 3) == 0) { + uint32_t *a32 = (uint32_t *)a; + uint32_t *b32 = (uint32_t *)b; + + while (count >= 4 && *a32 == *b32) { + a32++; + b32++; + count -= 4; + } + a = (const unsigned char *)a32; + b = (const unsigned char *)b32; + } + while (count-- > 0) { int cmp = *a++ - *b++; if (cmp != 0) diff --git a/src/system/libroot/posix/string/strcmp.c b/src/system/libroot/posix/string/strcmp.c index 8ac20d9499..db69903c58 100644 --- a/src/system/libroot/posix/string/strcmp.c +++ b/src/system/libroot/posix/string/strcmp.c @@ -4,9 +4,8 @@ */ -#include +#include #include -#include #define LACKS_ZERO_BYTE(value) \ @@ -16,8 +15,8 @@ int strcmp(char const *a, char const *b) { if ((((addr_t)a) & 3) == 0 && (((addr_t)b) & 3) == 0) { - uint32* a32 = (uint32*)a; - uint32* b32 = (uint32*)b; + uint32_t *a32 = (uint32_t *)a; + uint32_t *b32 = (uint32_t *)b; while (*a32 == *b32 && LACKS_ZERO_BYTE((*a32))) { a32++; @@ -27,7 +26,7 @@ strcmp(char const *a, char const *b) b = (const char *)b32; } - while (true) { + while (1) { int cmp = (unsigned char)*a - (unsigned char)*b++; if (cmp != 0 || *a++ == '\0') return cmp;