diffcore-delta: 64-byte-or-EOL ultrafast replacement.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Mar 15, 2006 at 00:37 UTC
3c7ceba4f1e8be1a536dd0e21bc4f422873d08d2
1 file changed
+16
-18
diffcore-delta.c
+16
-18
@@ -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)
102
+ unsigned long hashval, int cnt)
103
{
104
int bucket, lim;
105
struct spanhash *h;
@@ -110,14 +110,14 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
110
h = &(top->data[bucket++]);
111
if (!h->cnt) {
112
h->hashval = hashval;
113
- h->cnt = 1;
113
+ h->cnt = cnt;
114
top->free--;
115
if (top->free < 0)
116
return spanhash_rehash(top);
117
return top;
118
}
119
if (h->hashval == hashval) {
120
- h->cnt++;
120
+ h->cnt += cnt;
121
return top;
122
}
123
if (lim <= bucket)
@@ -127,7 +127,7 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
127
128
static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
129
{
130
- int i;
130
+ int i, n;
131
unsigned long accum1, accum2, hashval;
132
struct spanhash_top *hash;
133
@@ -137,19 +137,20 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
137
hash->free = INITIAL_FREE(i);
138
memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
139
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;
142
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++;
144
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;
154
}
155
return hash;
156
}
@@ -166,9 +167,6 @@ int diffcore_count_changes(void *src, unsigned long src_size,
167
struct spanhash_top *src_count, *dst_count;
168
unsigned long sc, la;
169
169
- if (src_size < 8 || dst_size < 8)
170
- return -1;
171
-
170
src_count = dst_count = NULL;
171
if (src_count_p)
172
src_count = *src_count_p;