]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: faster strequal, memequal
authorGraham Miller <graham.miller@gmail.com>
Thu, 7 Oct 2010 07:13:24 +0000 (03:13 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 7 Oct 2010 07:13:24 +0000 (03:13 -0400)
Fixes #1161.

R=rsc, cwvh
CC=golang-dev
https://golang.org/cl/2317044

src/pkg/runtime/runtime.c

index 71eb8d6b56789af4053265277a7fbe7536e3b9af..4b09f7bcf7e61acd6d2d8d5f2fcfe737e6bc4949 100644 (file)
@@ -310,14 +310,18 @@ memhash(uint32 s, void *a)
 static uint32
 memequal(uint32 s, void *a, void *b)
 {
-       byte *ba, *bb;
+       byte *ba, *bb, *aend;
        uint32 i;
 
        ba = a;
        bb = b;
-       for(i=0; i<s; i++)
-               if(ba[i] != bb[i])
+       aend = ba+s;
+       while(ba != aend) {
+               if(*ba != *bb)
                        return 0;
+               ba++;
+               bb++;
+       }
        return 1;
 }
 
@@ -389,8 +393,13 @@ strhash(uint32 s, String *a)
 static uint32
 strequal(uint32 s, String *a, String *b)
 {
+       int32 alen;
+
        USED(s);
-       return cmpstring(*a, *b) == 0;
+       alen = a->len;
+       if(alen != b->len)
+               return false;
+       return memequal(alen, a->str, b->str);
 }
 
 static void