X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=diff-delta.c;h=676288701ec429805d887cf59e1683652dc70cba;hb=539d84fe0a661f4e273d8a22e74d55d2fafc7598;hp=dcd3f5572e2682d1ef94b030efe1682dc3f76b67;hpb=38fd0721d0a2a1a723bc28fc0817e3571987b1ef;p=git.git diff --git a/diff-delta.c b/diff-delta.c index dcd3f557..67628870 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -90,22 +90,35 @@ static struct index ** delta_index(const unsigned char *buf, /* * Now make sure none of the hash buckets has more entries than - * we're willing to test. Otherwise we short-circuit the entry - * list uniformly to still preserve a good repartition across - * the reference buffer. + * we're willing to test. Otherwise we cull the entry list to + * limit identical three byte prefixes to still preserve a good + * repartition across the reference buffer. */ for (i = 0; i < hsize; i++) { + struct index **list, *bucket, *remaining; + int cnt; if (hash_count[i] < hlimit) continue; - entry = hash[i]; - do { - struct index *keep = entry; - int skip = hash_count[i] / hlimit / 2; - do { - entry = entry->next; - } while(--skip && entry); - keep->next = entry; - } while(entry); + + bucket = NULL; + list = &bucket; + remaining = hash[i]; + cnt = 0; + while (cnt < hlimit && remaining) { + struct index *this = remaining, *that; + remaining = remaining->next; + for (that = bucket; that; that = that->next) { + if (!memcmp(that->ptr, this->ptr, 3)) + break; + } + if (that) + continue; /* discard */ + cnt++; + *list = this; + list = &(this->next); + this->next = NULL; + } + hash[i] = bucket; } free(hash_count);