aboutsummaryrefslogtreecommitdiffstats
path: root/diffcore-rename.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-06 23:30:35 +0000
committerJunio C Hamano <gitster@pobox.com>2019-10-07 10:20:10 +0900
commitf0e63c41139f8982add435536d39aff6f3d4ca98 (patch)
tree6ed9e3afe2081c8201d6c6c9a0d9b8c9439d3a6e /diffcore-rename.c
parent6bcbdfb277bdc81b5ad6996b3fb005382a35c2ee (diff)
downloadgit-f0e63c41139f8982add435536d39aff6f3d4ca98.tar.gz
hashmap: use *_entry APIs to wrap container_of
Using `container_of' can be verbose and choosing names for intermediate "struct hashmap_entry" pointers is a hard problem. So introduce "*_entry" APIs inspired by similar linked-list APIs in the Linux kernel. Unfortunately, `__typeof__' is not portable C, so we need an extra parameter to specify the type. Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diffcore-rename.c')
-rw-r--r--diffcore-rename.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 71aa240a68..611b08f463 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -274,23 +274,19 @@ static int find_identical_files(struct hashmap *srcs,
struct diff_options *options)
{
int renames = 0;
- struct hashmap_entry *ent;
struct diff_filespec *target = rename_dst[dst_index].two;
struct file_similarity *p, *best = NULL;
int i = 100, best_score = -1;
+ unsigned int hash = hash_filespec(options->repo, target);
/*
* Find the best source match for specified destination.
*/
- ent = hashmap_get_from_hash(srcs,
- hash_filespec(options->repo, target),
- NULL);
- for (; ent; ent = hashmap_get_next(srcs, ent)) {
+ p = hashmap_get_entry_from_hash(srcs, hash, NULL,
+ struct file_similarity, entry);
+ hashmap_for_each_entry_from(srcs, p, struct file_similarity, entry) {
int score;
- struct diff_filespec *source;
-
- p = container_of(ent, struct file_similarity, entry);
- source = p->filespec;
+ struct diff_filespec *source = p->filespec;
/* False hash collision? */
if (!oideq(&source->oid, &target->oid))