Skip to content

Commit 3c7ceba

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
diffcore-delta: 64-byte-or-EOL ultrafast replacement.
Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 90bd932 commit 3c7ceba

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

diffcore-delta.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
102+
unsigned long hashval, int cnt)
103103
{
104104
int bucket, lim;
105105
struct spanhash *h;
@@ -110,14 +110,14 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
110110
h = &(top->data[bucket++]);
111111
if (!h->cnt) {
112112
h->hashval = hashval;
113-
h->cnt = 1;
113+
h->cnt = cnt;
114114
top->free--;
115115
if (top->free < 0)
116116
return spanhash_rehash(top);
117117
return top;
118118
}
119119
if (h->hashval == hashval) {
120-
h->cnt++;
120+
h->cnt += cnt;
121121
return top;
122122
}
123123
if (lim <= bucket)
@@ -127,7 +127,7 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
127127

128128
static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
129129
{
130-
int i;
130+
int i, n;
131131
unsigned long accum1, accum2, hashval;
132132
struct spanhash_top *hash;
133133

@@ -137,19 +137,20 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
137137
hash->free = INITIAL_FREE(i);
138138
memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
139139

140-
/* an 8-byte shift register made of accum1 and accum2. New
141-
* bytes come at LSB of accum2, and shifted up to accum1
142-
*/
143-
for (i = accum1 = accum2 = 0; i < 7; i++, sz--) {
144-
accum1 = (accum1 << 8) | (accum2 >> 24);
145-
accum2 = (accum2 << 8) | *buf++;
146-
}
140+
n = 0;
141+
accum1 = accum2 = 0;
147142
while (sz) {
148-
accum1 = (accum1 << 8) | (accum2 >> 24);
149-
accum2 = (accum2 << 8) | *buf++;
150-
hashval = (accum1 + accum2 * 0x61) % HASHBASE;
151-
hash = add_spanhash(hash, hashval);
143+
unsigned long c = *buf++;
152144
sz--;
145+
accum1 = (accum1 << 7) | (accum2 >> 25);
146+
accum2 = (accum2 << 7) | (accum1 >> 25);
147+
accum1 += c;
148+
if (++n < 64 && c != '\n')
149+
continue;
150+
hashval = (accum1 + accum2 * 0x61) % HASHBASE;
151+
hash = add_spanhash(hash, hashval, n);
152+
n = 0;
153+
accum1 = accum2 = 0;
153154
}
154155
return hash;
155156
}
@@ -166,9 +167,6 @@ int diffcore_count_changes(void *src, unsigned long src_size,
166167
struct spanhash_top *src_count, *dst_count;
167168
unsigned long sc, la;
168169

169-
if (src_size < 8 || dst_size < 8)
170-
return -1;
171-
172170
src_count = dst_count = NULL;
173171
if (src_count_p)
174172
src_count = *src_count_p;

0 commit comments

Comments
 (0)