diffcore-delta: make the hash a bit denser.
To reduce wasted memory, wait until the hash fills up more densely before we rehash. This reduces the working set size a bit further. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 12, 2006 at 16:39 UTC
2821104db7fabdfac105ae757228b0eac107047c
2 files changed
+11
-6
diffcore-delta.c
+9
-4
@@ -25,8 +25,12 @@
25
*/
26
27
/* Wild guess at the initial hash size */
28
-#define INITIAL_HASH_SIZE 10
28
+#define INITIAL_HASH_SIZE 9
29
#define HASHBASE 65537 /* next_prime(2^16) */
30
+/* We leave more room in smaller hash but do not let it
31
+ * grow to have unused hole too much.
32
+ */
33
+#define INITIAL_FREE(sz_log2) ((1<<(sz_log2))*(sz_log2-3)/(sz_log2))
34
35
struct spanhash {
36
unsigned long hashval;
@@ -38,7 +42,8 @@ struct spanhash_top {
42
struct spanhash data[FLEX_ARRAY];
43
};
44
41
-static struct spanhash *spanhash_find(struct spanhash_top *top, unsigned long hashval)
45
+static struct spanhash *spanhash_find(struct spanhash_top *top,
46
+ unsigned long hashval)
47
{
48
int sz = 1 << top->alloc_log2;
49
int bucket = hashval & (sz - 1);
@@ -62,7 +67,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
67
68
new = xmalloc(sizeof(*orig) + sizeof(struct spanhash) * sz);
69
new->alloc_log2 = orig->alloc_log2 + 1;
65
- new->free = osz;
70
+ new->free = INITIAL_FREE(new->alloc_log2);
71
memset(new->data, 0, sizeof(struct spanhash) * sz);
72
for (i = 0; i < osz; i++) {
73
struct spanhash *o = &(orig->data[i]);
@@ -122,7 +127,7 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
127
i = INITIAL_HASH_SIZE;
128
hash = xmalloc(sizeof(*hash) + sizeof(struct spanhash) * (1<<i));
129
hash->alloc_log2 = i;
125
- hash->free = (1<<i)/2;
130
+ hash->free = INITIAL_FREE(i);
131
memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
132
133
/* an 8-byte shift register made of accum1 and accum2. New
diffcore-rename.c
+2
-2
@@ -307,8 +307,8 @@ void diffcore_rename(struct diff_options *options)
307
m->score = estimate_similarity(one, two,
308
minimum_score);
309
}
310
- free(two->cnt_data);
311
- two->cnt_data = NULL;
310
+ /* We do not need the text anymore */
311
+ diff_free_filespec_data(two);
312
dst_cnt++;
313
}
314
/* cost matrix sorted by most to least similar pair */