Skip to content

Commit e31c9f2

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
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>
1 parent 3c7ceba commit e31c9f2

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

diffcore-delta.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#define HASHBASE 107927
4141

4242
struct spanhash {
43-
unsigned long hashval;
44-
unsigned long cnt;
43+
unsigned int hashval;
44+
unsigned int cnt;
4545
};
4646
struct spanhash_top {
4747
int alloc_log2;
@@ -50,7 +50,7 @@ struct spanhash_top {
5050
};
5151

5252
static struct spanhash *spanhash_find(struct spanhash_top *top,
53-
unsigned long hashval)
53+
unsigned int hashval)
5454
{
5555
int sz = 1 << top->alloc_log2;
5656
int bucket = hashval & (sz - 1);
@@ -99,7 +99,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
9999
}
100100

101101
static struct spanhash_top *add_spanhash(struct spanhash_top *top,
102-
unsigned long hashval, int cnt)
102+
unsigned int hashval, int cnt)
103103
{
104104
int bucket, lim;
105105
struct spanhash *h;
@@ -125,10 +125,10 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
125125
}
126126
}
127127

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)
129129
{
130130
int i, n;
131-
unsigned long accum1, accum2, hashval;
131+
unsigned int accum1, accum2, hashval;
132132
struct spanhash_top *hash;
133133

134134
i = INITIAL_HASH_SIZE;
@@ -140,10 +140,11 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
140140
n = 0;
141141
accum1 = accum2 = 0;
142142
while (sz) {
143-
unsigned long c = *buf++;
143+
unsigned int c = *buf++;
144+
unsigned int old_1 = accum1;
144145
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);
147148
accum1 += c;
148149
if (++n < 64 && c != '\n')
149150
continue;

0 commit comments

Comments
 (0)