44#include "cache.h"
55#include "diff.h"
66#include "diffcore.h"
7- #include "hash .h"
7+ #include "hashmap .h"
88#include "progress.h"
99
1010/* Table of rename/copy destinations */
@@ -243,9 +243,9 @@ static int score_compare(const void *a_, const void *b_)
243243}
244244
245245struct file_similarity {
246+ struct hashmap_entry entry ;
246247 int index ;
247248 struct diff_filespec * filespec ;
248- struct file_similarity * next ;
249249};
250250
251251static unsigned int hash_filespec (struct diff_filespec * filespec )
@@ -260,21 +260,22 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
260260 return hash ;
261261}
262262
263- static int find_identical_files (struct hash_table * srcs ,
263+ static int find_identical_files (struct hashmap * srcs ,
264264 int dst_index ,
265265 struct diff_options * options )
266266{
267267 int renames = 0 ;
268268
269269 struct diff_filespec * target = rename_dst [dst_index ].two ;
270- struct file_similarity * p , * best ;
270+ struct file_similarity * p , * best , dst ;
271271 int i = 100 , best_score = -1 ;
272272
273273 /*
274274 * Find the best source match for specified destination.
275275 */
276276 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 )) {
278279 int score ;
279280 struct diff_filespec * source = p -> filespec ;
280281
@@ -309,34 +310,15 @@ static int find_identical_files(struct hash_table *srcs,
309310 return renames ;
310311}
311312
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 )
313314{
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 ;
326315 struct file_similarity * entry = xmalloc (sizeof (* entry ));
327316
328317 entry -> index = index ;
329318 entry -> filespec = filespec ;
330- entry -> next = NULL ;
331-
332- hash = hash_filespec (filespec );
333- pos = insert_hash (hash , entry , table );
334319
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 );
340322}
341323
342324/*
@@ -349,23 +331,19 @@ static void insert_file_table(struct hash_table *table, int index, struct diff_f
349331static int find_exact_renames (struct diff_options * options )
350332{
351333 int i , renames = 0 ;
352- struct hash_table file_table ;
334+ struct hashmap file_table ;
353335
354336 /* 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 );
357338 for (i = 0 ; i < rename_src_nr ; i ++ )
358339 insert_file_table (& file_table , i , rename_src [i ].p -> one );
359340
360341 /* Walk the destinations and find best source match */
361342 for (i = 0 ; i < rename_dst_nr ; i ++ )
362343 renames += find_identical_files (& file_table , i , options );
363344
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 );
369347
370348 return renames ;
371349}
0 commit comments