X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=diffcore-delta.c;h=7338a40c5964ae6ddfb855465249fc1a2fa5a2a3;hb=7612a1efdb0c0806b43db10ce784707aae874340;hp=835d82c9939644faa808bb2f616136549af521db;hpb=fc66d213f8b2f13b9ffd643f01de25ddc95e0972;p=git.git diff --git a/diffcore-delta.c b/diffcore-delta.c index 835d82c9..7338a40c 100644 --- a/diffcore-delta.c +++ b/diffcore-delta.c @@ -40,8 +40,8 @@ #define HASHBASE 107927 struct spanhash { - unsigned long hashval; - unsigned long cnt; + unsigned int hashval; + unsigned int cnt; }; struct spanhash_top { int alloc_log2; @@ -50,7 +50,7 @@ struct spanhash_top { }; static struct spanhash *spanhash_find(struct spanhash_top *top, - unsigned long hashval) + unsigned int hashval) { int sz = 1 << top->alloc_log2; int bucket = hashval & (sz - 1); @@ -99,7 +99,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig) } static struct spanhash_top *add_spanhash(struct spanhash_top *top, - unsigned long hashval) + unsigned int hashval, int cnt) { int bucket, lim; struct spanhash *h; @@ -110,14 +110,14 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top, h = &(top->data[bucket++]); if (!h->cnt) { h->hashval = hashval; - h->cnt = 1; + h->cnt = cnt; top->free--; if (top->free < 0) return spanhash_rehash(top); return top; } if (h->hashval == hashval) { - h->cnt++; + h->cnt += cnt; return top; } if (lim <= bucket) @@ -125,10 +125,10 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top, } } -static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz) +static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz) { - int i; - unsigned long accum1, accum2, hashval; + int i, n; + unsigned int accum1, accum2, hashval; struct spanhash_top *hash; i = INITIAL_HASH_SIZE; @@ -137,19 +137,21 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz) hash->free = INITIAL_FREE(i); memset(hash->data, 0, sizeof(struct spanhash) * (1<> 24); - accum2 = (accum2 << 8) | *buf++; - } + n = 0; + accum1 = accum2 = 0; while (sz) { - accum1 = (accum1 << 8) | (accum2 >> 24); - accum2 = (accum2 << 8) | *buf++; - hashval = (accum1 + accum2 * 0x61) % HASHBASE; - hash = add_spanhash(hash, hashval); + unsigned int c = *buf++; + unsigned int old_1 = accum1; sz--; + accum1 = (accum1 << 7) ^ (accum2 >> 25); + accum2 = (accum2 << 7) ^ (old_1 >> 25); + accum1 += c; + if (++n < 64 && c != '\n') + continue; + hashval = (accum1 + accum2 * 0x61) % HASHBASE; + hash = add_spanhash(hash, hashval, n); + n = 0; + accum1 = accum2 = 0; } return hash; } @@ -166,9 +168,6 @@ int diffcore_count_changes(void *src, unsigned long src_size, struct spanhash_top *src_count, *dst_count; unsigned long sc, la; - if (src_size < 8 || dst_size < 8) - return -1; - src_count = dst_count = NULL; if (src_count_p) src_count = *src_count_p;