@matheusbsbs / matheus-bagliano / commits / e31c9f241a
Fork 0

diffcore-delta: 64-byte-or-EOL ultrafast replacement (hash fix).

The rotating 64-bit number was not really rotating, and worse yet ulong was longer than 64-bit on 64-bit architectures X-<. Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Mar 15, 2006 at 00:37 UTC e31c9f241ae5469c820cde2a54987a1075e52a43
1 file changed +10 -9
diffcore-delta.c
+10 -9
@@ -40,8 +40,8 @@
40 #define HASHBASE 107927
41
42 struct spanhash {
43 - unsigned long hashval;
44 - unsigned long cnt;
43 + unsigned int hashval;
44 + unsigned int cnt;
45 };
46 struct spanhash_top {
47 int alloc_log2;
@@ -50,7 +50,7 @@ struct spanhash_top {
50 };
51
52 static struct spanhash *spanhash_find(struct spanhash_top *top,
53 - unsigned long hashval)
53 + unsigned int hashval)
54 {
55 int sz = 1 << top->alloc_log2;
56 int bucket = hashval & (sz - 1);
@@ -99,7 +99,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
99 }
100
101 static struct spanhash_top *add_spanhash(struct spanhash_top *top,
102 - unsigned long hashval, int cnt)
102 + unsigned int hashval, int cnt)
103 {
104 int bucket, lim;
105 struct spanhash *h;
@@ -125,10 +125,10 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
125 }
126 }
127
128 -static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
128 +static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz)
129 {
130 int i, n;
131 - unsigned long accum1, accum2, hashval;
131 + unsigned int accum1, accum2, hashval;
132 struct spanhash_top *hash;
133
134 i = INITIAL_HASH_SIZE;
@@ -140,10 +140,11 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
140 n = 0;
141 accum1 = accum2 = 0;
142 while (sz) {
143 - unsigned long c = *buf++;
143 + unsigned int c = *buf++;
144 + unsigned int old_1 = accum1;
145 sz--;
145 - accum1 = (accum1 << 7) | (accum2 >> 25);
146 - accum2 = (accum2 << 7) | (accum1 >> 25);
146 + accum1 = (accum1 << 7) ^ (accum2 >> 25);
147 + accum2 = (accum2 << 7) ^ (old_1 >> 25);
148 accum1 += c;
149 if (++n < 64 && c != '\n')
150 continue;