Reintroduce aligned-pointers optimization for strcmp.
It was initially added by tqh inac827a2baa, but was later removed in39a81e5ac6due to being rather broken. This new version is loosely based on that design, but removes the comparison logic out of the loop and lets the unaligned version deal with the actual per-character comparison. Saves around 0.1s out of 3.5s in the best case in a "jam -q HaikuDepot" run with nothing to do (and that's only comparing with different libroots on the same kernel; as this strcmp is used in the kernel as well, we will benefit from this optimization there, too.)
This commit is contained in:
@@ -15,6 +15,18 @@
|
||||
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;
|
||||
|
||||
while (*a32 == *b32 && LACKS_ZERO_BYTE((*a32))) {
|
||||
a32++;
|
||||
b32++;
|
||||
}
|
||||
a = (const char *)a32;
|
||||
b = (const char *)b32;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
int cmp = (unsigned char)*a - (unsigned char)*b++;
|
||||
if (cmp != 0 || *a++ == '\0')
|
||||
|
||||
Reference in New Issue
Block a user