diffcore-rename.c: use new hash map implementation

Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Nov 14, 2013 at 20:20 UTC f79d9c581437d8f48e10506e62c34b9718c7f3f7
1 file changed +13 -35
diffcore-rename.c
+13 -35
@@ -4,7 +4,7 @@
4 #include "cache.h"
5 #include "diff.h"
6 #include "diffcore.h"
7 -#include "hash.h"
7 +#include "hashmap.h"
8 #include "progress.h"
9
10 /* Table of rename/copy destinations */
@@ -243,9 +243,9 @@ static int score_compare(const void *a_, const void *b_)
243 }
244
245 struct file_similarity {
246 + struct hashmap_entry entry;
247 int index;
248 struct diff_filespec *filespec;
248 - struct file_similarity *next;
249 };
250
251 static unsigned int hash_filespec(struct diff_filespec *filespec)
@@ -260,21 +260,22 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
260 return hash;
261 }
262
263 -static int find_identical_files(struct hash_table *srcs,
263 +static int find_identical_files(struct hashmap *srcs,
264 int dst_index,
265 struct diff_options *options)
266 {
267 int renames = 0;
268
269 struct diff_filespec *target = rename_dst[dst_index].two;
270 - struct file_similarity *p, *best;
270 + struct file_similarity *p, *best, dst;
271 int i = 100, best_score = -1;
272
273 /*
274 * Find the best source match for specified destination.
275 */
276 best = NULL;
277 - for (p = lookup_hash(hash_filespec(target), srcs); p; p = p->next) {
277 + hashmap_entry_init(&dst, hash_filespec(target));
278 + for (p = hashmap_get(srcs, &dst, NULL); p; p = hashmap_get_next(srcs, p)) {
279 int score;
280 struct diff_filespec *source = p->filespec;
281
@@ -309,34 +310,15 @@ static int find_identical_files(struct hash_table *srcs,
310 return renames;
311 }
312
312 -static int free_similarity_list(void *p, void *unused)
313 +static void insert_file_table(struct hashmap *table, int index, struct diff_filespec *filespec)
314 {
314 - while (p) {
315 - struct file_similarity *entry = p;
316 - p = entry->next;
317 - free(entry);
318 - }
319 - return 0;
320 -}
321 -
322 -static void insert_file_table(struct hash_table *table, int index, struct diff_filespec *filespec)
323 -{
324 - void **pos;
325 - unsigned int hash;
315 struct file_similarity *entry = xmalloc(sizeof(*entry));
316
317 entry->index = index;
318 entry->filespec = filespec;
330 - entry->next = NULL;
331 -
332 - hash = hash_filespec(filespec);
333 - pos = insert_hash(hash, entry, table);
319
335 - /* We already had an entry there? */
336 - if (pos) {
337 - entry->next = *pos;
338 - *pos = entry;
339 - }
320 + hashmap_entry_init(entry, hash_filespec(filespec));
321 + hashmap_add(table, entry);
322 }
323
324 /*
@@ -349,11 +331,10 @@ static void insert_file_table(struct hash_table *table, int index, struct diff_f
331 static int find_exact_renames(struct diff_options *options)
332 {
333 int i, renames = 0;
352 - struct hash_table file_table;
334 + struct hashmap file_table;
335
336 /* Add all sources to the hash table */
355 - init_hash(&file_table);
356 - preallocate_hash(&file_table, rename_src_nr);
337 + hashmap_init(&file_table, NULL, rename_src_nr);
338 for (i = 0; i < rename_src_nr; i++)
339 insert_file_table(&file_table, i, rename_src[i].p->one);
340
@@ -361,11 +342,8 @@ static int find_exact_renames(struct diff_options *options)
342 for (i = 0; i < rename_dst_nr; i++)
343 renames += find_identical_files(&file_table, i, options);
344
364 - /* Free source file_similarity chains */
365 - for_each_hash(&file_table, free_similarity_list, options);
366 -
367 - /* .. and free the hash data structure */
368 - free_hash(&file_table);
345 + /* Free the hash data structure and entries */
346 + hashmap_free(&file_table, 1);
347
348 return renames;
349 }