hashmap_cmp_fn takes hashmap_entry params
Another step in eliminating the requirement of hashmap_entry being the first member of a struct. Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
Oct 6, 2019 at 23:30 UTC
939af16eac1608766273d3971598dbcc4fe09928
23 files changed
+204
-115
attr.c
+6
-4
@@ -70,12 +70,14 @@ struct attr_hash_entry {
70
71
/* attr_hashmap comparison function */
72
static int attr_hash_entry_cmp(const void *unused_cmp_data,
73
- const void *entry,
74
- const void *entry_or_key,
73
+ const struct hashmap_entry *eptr,
74
+ const struct hashmap_entry *entry_or_key,
75
const void *unused_keydata)
76
{
77
- const struct attr_hash_entry *a = entry;
78
- const struct attr_hash_entry *b = entry_or_key;
77
+ const struct attr_hash_entry *a, *b;
78
+
79
+ a = container_of(eptr, const struct attr_hash_entry, ent);
80
+ b = container_of(entry_or_key, const struct attr_hash_entry, ent);
81
return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
82
}
83
builtin/describe.c
+6
-4
@@ -64,12 +64,14 @@ static const char *prio_names[] = {
64
};
65
66
static int commit_name_neq(const void *unused_cmp_data,
67
- const void *entry,
68
- const void *entry_or_key,
67
+ const struct hashmap_entry *eptr,
68
+ const struct hashmap_entry *entry_or_key,
69
const void *peeled)
70
{
71
- const struct commit_name *cn1 = entry;
72
- const struct commit_name *cn2 = entry_or_key;
71
+ const struct commit_name *cn1, *cn2;
72
+
73
+ cn1 = container_of(eptr, const struct commit_name, entry);
74
+ cn2 = container_of(entry_or_key, const struct commit_name, entry);
75
76
return !oideq(&cn1->peeled, peeled ? peeled : &cn2->peeled);
77
}
builtin/difftool.c
+19
-12
@@ -125,12 +125,15 @@ struct working_tree_entry {
125
};
126
127
static int working_tree_entry_cmp(const void *unused_cmp_data,
128
- const void *entry,
129
- const void *entry_or_key,
128
+ const struct hashmap_entry *eptr,
129
+ const struct hashmap_entry *entry_or_key,
130
const void *unused_keydata)
131
{
132
- const struct working_tree_entry *a = entry;
133
- const struct working_tree_entry *b = entry_or_key;
132
+ const struct working_tree_entry *a, *b;
133
+
134
+ a = container_of(eptr, const struct working_tree_entry, entry);
135
+ b = container_of(entry_or_key, const struct working_tree_entry, entry);
136
+
137
return strcmp(a->path, b->path);
138
}
139
@@ -145,12 +148,14 @@ struct pair_entry {
148
};
149
150
static int pair_cmp(const void *unused_cmp_data,
148
- const void *entry,
149
- const void *entry_or_key,
151
+ const struct hashmap_entry *eptr,
152
+ const struct hashmap_entry *entry_or_key,
153
const void *unused_keydata)
154
{
152
- const struct pair_entry *a = entry;
153
- const struct pair_entry *b = entry_or_key;
155
+ const struct pair_entry *a, *b;
156
+
157
+ a = container_of(eptr, const struct pair_entry, entry);
158
+ b = container_of(entry_or_key, const struct pair_entry, entry);
159
160
return strcmp(a->path, b->path);
161
}
@@ -179,12 +184,14 @@ struct path_entry {
184
};
185
186
static int path_entry_cmp(const void *unused_cmp_data,
182
- const void *entry,
183
- const void *entry_or_key,
187
+ const struct hashmap_entry *eptr,
188
+ const struct hashmap_entry *entry_or_key,
189
const void *key)
190
{
186
- const struct path_entry *a = entry;
187
- const struct path_entry *b = entry_or_key;
191
+ const struct path_entry *a, *b;
192
+
193
+ a = container_of(eptr, const struct path_entry, entry);
194
+ b = container_of(entry_or_key, const struct path_entry, entry);
195
196
return strcmp(a->path, key ? key : b->path);
197
}
builtin/fast-export.c
+7
-2
@@ -126,10 +126,15 @@ struct anonymized_entry {
126
};
127
128
static int anonymized_entry_cmp(const void *unused_cmp_data,
129
- const void *va, const void *vb,
129
+ const struct hashmap_entry *eptr,
130
+ const struct hashmap_entry *entry_or_key,
131
const void *unused_keydata)
132
{
132
- const struct anonymized_entry *a = va, *b = vb;
133
+ const struct anonymized_entry *a, *b;
134
+
135
+ a = container_of(eptr, const struct anonymized_entry, hash);
136
+ b = container_of(entry_or_key, const struct anonymized_entry, hash);
137
+
138
return a->orig_len != b->orig_len ||
139
memcmp(a->orig, b->orig, a->orig_len);
140
}
builtin/fetch.c
+5
-4
@@ -258,13 +258,14 @@ struct refname_hash_entry {
258
};
259
260
static int refname_hash_entry_cmp(const void *hashmap_cmp_fn_data,
261
- const void *e1_,
262
- const void *e2_,
261
+ const struct hashmap_entry *eptr,
262
+ const struct hashmap_entry *entry_or_key,
263
const void *keydata)
264
{
265
- const struct refname_hash_entry *e1 = e1_;
266
- const struct refname_hash_entry *e2 = e2_;
265
+ const struct refname_hash_entry *e1, *e2;
266
267
+ e1 = container_of(eptr, const struct refname_hash_entry, ent);
268
+ e2 = container_of(entry_or_key, const struct refname_hash_entry, ent);
269
return strcmp(e1->refname, keydata ? keydata : e2->refname);
270
}
271
config.c
+6
-4
@@ -1914,12 +1914,14 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
1914
}
1915
1916
static int config_set_element_cmp(const void *unused_cmp_data,
1917
- const void *entry,
1918
- const void *entry_or_key,
1917
+ const struct hashmap_entry *eptr,
1918
+ const struct hashmap_entry *entry_or_key,
1919
const void *unused_keydata)
1920
{
1921
- const struct config_set_element *e1 = entry;
1922
- const struct config_set_element *e2 = entry_or_key;
1921
+ const struct config_set_element *e1, *e2;
1922
+
1923
+ e1 = container_of(eptr, const struct config_set_element, ent);
1924
+ e2 = container_of(entry_or_key, const struct config_set_element, ent);
1925
1926
return strcmp(e1->key, e2->key);
1927
}
diff.c
+7
-5
@@ -933,16 +933,18 @@ static int cmp_in_block_with_wsd(const struct diff_options *o,
933
}
934
935
static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
936
- const void *entry,
937
- const void *entry_or_key,
936
+ const struct hashmap_entry *eptr,
937
+ const struct hashmap_entry *entry_or_key,
938
const void *keydata)
939
{
940
const struct diff_options *diffopt = hashmap_cmp_fn_data;
941
- const struct moved_entry *a = entry;
942
- const struct moved_entry *b = entry_or_key;
941
+ const struct moved_entry *a, *b;
942
unsigned flags = diffopt->color_moved_ws_handling
943
& XDF_WHITESPACE_FLAGS;
944
945
+ a = container_of(eptr, const struct moved_entry, ent);
946
+ b = container_of(entry_or_key, const struct moved_entry, ent);
947
+
948
if (diffopt->color_moved_ws_handling &
949
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
950
/*
@@ -1019,7 +1021,7 @@ static void pmb_advance_or_null(struct diff_options *o,
1021
struct moved_entry *prev = pmb[i].match;
1022
struct moved_entry *cur = (prev && prev->next_line) ?
1023
prev->next_line : NULL;
1022
- if (cur && !hm->cmpfn(o, cur, match, NULL)) {
1024
+ if (cur && !hm->cmpfn(o, &cur->ent, &match->ent, NULL)) {
1025
pmb[i].match = cur;
1026
} else {
1027
pmb[i].match = NULL;
hashmap.c
+11
-6
@@ -140,8 +140,8 @@ static inline struct hashmap_entry **find_entry_ptr(const struct hashmap *map,
140
}
141
142
static int always_equal(const void *unused_cmp_data,
143
- const void *unused1,
144
- const void *unused2,
143
+ const struct hashmap_entry *unused1,
144
+ const struct hashmap_entry *unused2,
145
const void *unused_keydata)
146
{
147
return 0;
@@ -279,10 +279,15 @@ struct pool_entry {
279
};
280
281
static int pool_entry_cmp(const void *unused_cmp_data,
282
- const struct pool_entry *e1,
283
- const struct pool_entry *e2,
284
- const unsigned char *keydata)
282
+ const struct hashmap_entry *eptr,
283
+ const struct hashmap_entry *entry_or_key,
284
+ const void *keydata)
285
{
286
+ const struct pool_entry *e1, *e2;
287
+
288
+ e1 = container_of(eptr, const struct pool_entry, ent);
289
+ e2 = container_of(entry_or_key, const struct pool_entry, ent);
290
+
291
return e1->data != keydata &&
292
(e1->len != e2->len || memcmp(e1->data, keydata, e1->len));
293
}
@@ -294,7 +299,7 @@ const void *memintern(const void *data, size_t len)
299
300
/* initialize string pool hashmap */
301
if (!map.tablesize)
297
- hashmap_init(&map, (hashmap_cmp_fn) pool_entry_cmp, NULL, 0);
302
+ hashmap_init(&map, pool_entry_cmp, NULL, 0);
303
304
/* lookup interned string in pool */
305
hashmap_entry_init(&key.ent, memhash(data, len));
hashmap.h
+9
-4
@@ -21,12 +21,16 @@
21
* #define COMPARE_VALUE 1
22
*
23
* static int long2string_cmp(const void *hashmap_cmp_fn_data,
24
- * const struct long2string *e1,
25
- * const struct long2string *e2,
24
+ * const struct hashmap_entry *eptr,
25
+ * const struct hashmap_entry *entry_or_key,
26
* const void *keydata)
27
* {
28
* const char *string = keydata;
29
* unsigned flags = *(unsigned *)hashmap_cmp_fn_data;
30
+ * const struct long2string *e1, *e2;
31
+ *
32
+ * e1 = container_of(eptr, const struct long2string, ent);
33
+ * e2 = container_of(entry_or_key, const struct long2string, ent);
34
*
35
* if (flags & COMPARE_VALUE)
36
* return e1->key != e2->key ||
@@ -41,7 +45,7 @@
45
* char value[255], action[32];
46
* unsigned flags = 0;
47
*
44
- * hashmap_init(&map, (hashmap_cmp_fn) long2string_cmp, &flags, 0);
48
+ * hashmap_init(&map, long2string_cmp, &flags, 0);
49
*
50
* while (scanf("%s %ld %s", action, &key, value)) {
51
*
@@ -172,7 +176,8 @@ struct hashmap_entry {
176
* The `hashmap_cmp_fn_data` entry is the pointer given in the init function.
177
*/
178
typedef int (*hashmap_cmp_fn)(const void *hashmap_cmp_fn_data,
175
- const void *entry, const void *entry_or_key,
179
+ const struct hashmap_entry *entry,
180
+ const struct hashmap_entry *entry_or_key,
181
const void *keydata);
182
183
/*
merge-recursive.c
+21
-12
@@ -35,14 +35,16 @@ struct path_hashmap_entry {
35
};
36
37
static int path_hashmap_cmp(const void *cmp_data,
38
- const void *entry,
39
- const void *entry_or_key,
38
+ const struct hashmap_entry *eptr,
39
+ const struct hashmap_entry *entry_or_key,
40
const void *keydata)
41
{
42
- const struct path_hashmap_entry *a = entry;
43
- const struct path_hashmap_entry *b = entry_or_key;
42
+ const struct path_hashmap_entry *a, *b;
43
const char *key = keydata;
44
45
+ a = container_of(eptr, const struct path_hashmap_entry, e);
46
+ b = container_of(entry_or_key, const struct path_hashmap_entry, e);
47
+
48
if (ignore_case)
49
return strcasecmp(a->path, key ? key : b->path);
50
else
@@ -68,12 +70,14 @@ static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
70
}
71
72
static int dir_rename_cmp(const void *unused_cmp_data,
71
- const void *entry,
72
- const void *entry_or_key,
73
+ const struct hashmap_entry *eptr,
74
+ const struct hashmap_entry *entry_or_key,
75
const void *unused_keydata)
76
{
75
- const struct dir_rename_entry *e1 = entry;
76
- const struct dir_rename_entry *e2 = entry_or_key;
77
+ const struct dir_rename_entry *e1, *e2;
78
+
79
+ e1 = container_of(eptr, const struct dir_rename_entry, ent);
80
+ e2 = container_of(entry_or_key, const struct dir_rename_entry, ent);
81
82
return strcmp(e1->dir, e2->dir);
83
}
@@ -104,17 +108,22 @@ static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
108
struct collision_entry, ent);
109
}
110
107
-static int collision_cmp(void *unused_cmp_data,
108
- const struct collision_entry *e1,
109
- const struct collision_entry *e2,
111
+static int collision_cmp(const void *unused_cmp_data,
112
+ const struct hashmap_entry *eptr,
113
+ const struct hashmap_entry *entry_or_key,
114
const void *unused_keydata)
115
{
116
+ const struct collision_entry *e1, *e2;
117
+
118
+ e1 = container_of(eptr, const struct collision_entry, ent);
119
+ e2 = container_of(entry_or_key, const struct collision_entry, ent);
120
+
121
return strcmp(e1->target_file, e2->target_file);
122
}
123
124
static void collision_init(struct hashmap *map)
125
{
117
- hashmap_init(map, (hashmap_cmp_fn) collision_cmp, NULL, 0);
126
+ hashmap_init(map, collision_cmp, NULL, 0);
127
}
128
129
static void flush_output(struct merge_options *opt)
name-hash.c
+13
-8
@@ -17,14 +17,16 @@ struct dir_entry {
17
};
18
19
static int dir_entry_cmp(const void *unused_cmp_data,
20
- const void *entry,
21
- const void *entry_or_key,
20
+ const struct hashmap_entry *eptr,
21
+ const struct hashmap_entry *entry_or_key,
22
const void *keydata)
23
{
24
- const struct dir_entry *e1 = entry;
25
- const struct dir_entry *e2 = entry_or_key;
24
+ const struct dir_entry *e1, *e2;
25
const char *name = keydata;
26
27
+ e1 = container_of(eptr, const struct dir_entry, ent);
28
+ e2 = container_of(entry_or_key, const struct dir_entry, ent);
29
+
30
return e1->namelen != e2->namelen || strncasecmp(e1->name,
31
name ? name : e2->name, e1->namelen);
32
}
@@ -115,12 +117,15 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
117
}
118
119
static int cache_entry_cmp(const void *unused_cmp_data,
118
- const void *entry,
119
- const void *entry_or_key,
120
+ const struct hashmap_entry *eptr,
121
+ const struct hashmap_entry *entry_or_key,
122
const void *remove)
123
{
122
- const struct cache_entry *ce1 = entry;
123
- const struct cache_entry *ce2 = entry_or_key;
124
+ const struct cache_entry *ce1, *ce2;
125
+
126
+ ce1 = container_of(eptr, const struct cache_entry, ent);
127
+ ce2 = container_of(entry_or_key, const struct cache_entry, ent);
128
+
129
/*
130
* For remove_name_hash, find the exact entry (pointer equality); for
131
* index_file_exists, find all entries with matching hash code and
oidmap.c
+9
-5
@@ -2,14 +2,18 @@
2
#include "oidmap.h"
3
4
static int oidmap_neq(const void *hashmap_cmp_fn_data,
5
- const void *entry, const void *entry_or_key,
5
+ const struct hashmap_entry *e1,
6
+ const struct hashmap_entry *e2,
7
const void *keydata)
8
{
8
- const struct oidmap_entry *entry_ = entry;
9
+ const struct oidmap_entry *a, *b;
10
+
11
+ a = container_of(e1, const struct oidmap_entry, internal_entry);
12
+ b = container_of(e2, const struct oidmap_entry, internal_entry);
13
+
14
if (keydata)
10
- return !oideq(&entry_->oid, (const struct object_id *) keydata);
11
- return !oideq(&entry_->oid,
12
- &((const struct oidmap_entry *) entry_or_key)->oid);
15
+ return !oideq(&a->oid, (const struct object_id *) keydata);
16
+ return !oideq(&a->oid, &b->oid);
17
}
18
19
void oidmap_init(struct oidmap *map, size_t initial_size)
packfile.c
+7
-2
@@ -1401,11 +1401,16 @@ static int delta_base_cache_key_eq(const struct delta_base_cache_key *a,
1401
}
1402
1403
static int delta_base_cache_hash_cmp(const void *unused_cmp_data,
1404
- const void *va, const void *vb,
1404
+ const struct hashmap_entry *va,
1405
+ const struct hashmap_entry *vb,
1406
const void *vkey)
1407
{
1407
- const struct delta_base_cache_entry *a = va, *b = vb;
1408
+ const struct delta_base_cache_entry *a, *b;
1409
const struct delta_base_cache_key *key = vkey;
1410
+
1411
+ a = container_of(va, const struct delta_base_cache_entry, ent);
1412
+ b = container_of(vb, const struct delta_base_cache_entry, ent);
1413
+
1414
if (key)
1415
return !delta_base_cache_key_eq(&a->key, key);
1416
else
patch-ids.c
+6
-4
@@ -36,14 +36,16 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,
36
* any significance; only that it is non-zero matters.
37
*/
38
static int patch_id_neq(const void *cmpfn_data,
39
- const void *entry,
40
- const void *entry_or_key,
39
+ const struct hashmap_entry *eptr,
40
+ const struct hashmap_entry *entry_or_key,
41
const void *unused_keydata)
42
{
43
/* NEEDSWORK: const correctness? */
44
struct diff_options *opt = (void *)cmpfn_data;
45
- struct patch_id *a = (void *)entry;
46
- struct patch_id *b = (void *)entry_or_key;
45
+ struct patch_id *a, *b;
46
+
47
+ a = container_of(eptr, struct patch_id, ent);
48
+ b = container_of(entry_or_key, struct patch_id, ent);
49
50
if (is_null_oid(&a->patch_id) &&
51
commit_patch_id(a->commit, opt, &a->patch_id, 0, 0))
ref-filter.c
+7
-4
@@ -84,12 +84,15 @@ struct ref_to_worktree_entry {
84
};
85
86
static int ref_to_worktree_map_cmpfnc(const void *unused_lookupdata,
87
- const void *existing_hashmap_entry_to_test,
88
- const void *key,
87
+ const struct hashmap_entry *eptr,
88
+ const struct hashmap_entry *kptr,
89
const void *keydata_aka_refname)
90
{
91
- const struct ref_to_worktree_entry *e = existing_hashmap_entry_to_test;
92
- const struct ref_to_worktree_entry *k = key;
91
+ const struct ref_to_worktree_entry *e, *k;
92
+
93
+ e = container_of(eptr, const struct ref_to_worktree_entry, ent);
94
+ k = container_of(kptr, const struct ref_to_worktree_entry, ent);
95
+
96
return strcmp(e->wt->head_ref,
97
keydata_aka_refname ? keydata_aka_refname : k->wt->head_ref);
98
}
refs.c
+8
-3
@@ -1781,11 +1781,16 @@ struct ref_store_hash_entry
1781
};
1782
1783
static int ref_store_hash_cmp(const void *unused_cmp_data,
1784
- const void *entry, const void *entry_or_key,
1784
+ const struct hashmap_entry *eptr,
1785
+ const struct hashmap_entry *entry_or_key,
1786
const void *keydata)
1787
{
1787
- const struct ref_store_hash_entry *e1 = entry, *e2 = entry_or_key;
1788
- const char *name = keydata ? keydata : e2->name;
1788
+ const struct ref_store_hash_entry *e1, *e2;
1789
+ const char *name;
1790
+
1791
+ e1 = container_of(eptr, const struct ref_store_hash_entry, ent);
1792
+ e2 = container_of(entry_or_key, const struct ref_store_hash_entry, ent);
1793
+ name = keydata ? keydata : e2->name;
1794
1795
return strcmp(e1->name, name);
1796
}
remote.c
+6
-4
@@ -111,14 +111,16 @@ struct remotes_hash_key {
111
};
112
113
static int remotes_hash_cmp(const void *unused_cmp_data,
114
- const void *entry,
115
- const void *entry_or_key,
114
+ const struct hashmap_entry *eptr,
115
+ const struct hashmap_entry *entry_or_key,
116
const void *keydata)
117
{
118
- const struct remote *a = entry;
119
- const struct remote *b = entry_or_key;
118
+ const struct remote *a, *b;
119
const struct remotes_hash_key *key = keydata;
120
121
+ a = container_of(eptr, const struct remote, ent);
122
+ b = container_of(entry_or_key, const struct remote, ent);
123
+
124
if (key)
125
return strncmp(a->name, key->str, key->len) || a->name[key->len];
126
else
revision.c
+8
-3
@@ -107,16 +107,21 @@ struct path_and_oids_entry {
107
};
108
109
static int path_and_oids_cmp(const void *hashmap_cmp_fn_data,
110
- const struct path_and_oids_entry *e1,
111
- const struct path_and_oids_entry *e2,
110
+ const struct hashmap_entry *eptr,
111
+ const struct hashmap_entry *entry_or_key,
112
const void *keydata)
113
{
114
+ const struct path_and_oids_entry *e1, *e2;
115
+
116
+ e1 = container_of(eptr, const struct path_and_oids_entry, ent);
117
+ e2 = container_of(entry_or_key, const struct path_and_oids_entry, ent);
118
+
119
return strcmp(e1->path, e2->path);
120
}
121
122
static void paths_and_oids_init(struct hashmap *map)
123
{
119
- hashmap_init(map, (hashmap_cmp_fn) path_and_oids_cmp, NULL, 0);
124
+ hashmap_init(map, path_and_oids_cmp, NULL, 0);
125
}
126
127
static void paths_and_oids_clear(struct hashmap *map)
sequencer.c
+17
-7
@@ -4440,9 +4440,14 @@ struct labels_entry {
4440
char label[FLEX_ARRAY];
4441
};
4442
4443
-static int labels_cmp(const void *fndata, const struct labels_entry *a,
4444
- const struct labels_entry *b, const void *key)
4443
+static int labels_cmp(const void *fndata, const struct hashmap_entry *eptr,
4444
+ const struct hashmap_entry *entry_or_key, const void *key)
4445
{
4446
+ const struct labels_entry *a, *b;
4447
+
4448
+ a = container_of(eptr, const struct labels_entry, entry);
4449
+ b = container_of(entry_or_key, const struct labels_entry, entry);
4450
+
4451
return key ? strcmp(a->label, key) : strcmp(a->label, b->label);
4452
}
4453
@@ -4573,7 +4578,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
4578
4579
oidmap_init(&commit2todo, 0);
4580
oidmap_init(&state.commit2label, 0);
4576
- hashmap_init(&state.labels, (hashmap_cmp_fn) labels_cmp, NULL, 0);
4581
+ hashmap_init(&state.labels, labels_cmp, NULL, 0);
4582
strbuf_init(&state.buf, 32);
4583
4584
if (revs->cmdline.nr && (revs->cmdline.rev[0].flags & BOTTOM)) {
@@ -5138,9 +5143,15 @@ struct subject2item_entry {
5143
};
5144
5145
static int subject2item_cmp(const void *fndata,
5141
- const struct subject2item_entry *a,
5142
- const struct subject2item_entry *b, const void *key)
5146
+ const struct hashmap_entry *eptr,
5147
+ const struct hashmap_entry *entry_or_key,
5148
+ const void *key)
5149
{
5150
+ const struct subject2item_entry *a, *b;
5151
+
5152
+ a = container_of(eptr, const struct subject2item_entry, entry);
5153
+ b = container_of(entry_or_key, const struct subject2item_entry, entry);
5154
+
5155
return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject);
5156
}
5157
@@ -5173,8 +5184,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
5184
* In that case, last[i] will indicate the index of the latest item to
5185
* be moved to appear after the i'th.
5186
*/
5176
- hashmap_init(&subject2item, (hashmap_cmp_fn) subject2item_cmp,
5177
- NULL, todo_list->nr);
5187
+ hashmap_init(&subject2item, subject2item_cmp, NULL, todo_list->nr);
5188
ALLOC_ARRAY(next, todo_list->nr);
5189
ALLOC_ARRAY(tail, todo_list->nr);
5190
ALLOC_ARRAY(subjects, todo_list->nr);
sub-process.c
+6
-4
@@ -6,12 +6,14 @@
6
#include "pkt-line.h"
7
8
int cmd2process_cmp(const void *unused_cmp_data,
9
- const void *entry,
10
- const void *entry_or_key,
9
+ const struct hashmap_entry *eptr,
10
+ const struct hashmap_entry *entry_or_key,
11
const void *unused_keydata)
12
{
13
- const struct subprocess_entry *e1 = entry;
14
- const struct subprocess_entry *e2 = entry_or_key;
13
+ const struct subprocess_entry *e1, *e2;
14
+
15
+ e1 = container_of(eptr, const struct subprocess_entry, ent);
16
+ e2 = container_of(entry_or_key, const struct subprocess_entry, ent);
17
18
return strcmp(e1->cmd, e2->cmd);
19
}
sub-process.h
+2
-2
@@ -43,8 +43,8 @@ struct subprocess_capability {
43
44
/* Function to test two subprocess hashmap entries for equality. */
45
int cmd2process_cmp(const void *unused_cmp_data,
46
- const void *e1,
47
- const void *e2,
46
+ const struct hashmap_entry *e,
47
+ const struct hashmap_entry *entry_or_key,
48
const void *unused_keydata);
49
50
/*
submodule-config.c
+12
-8
@@ -38,24 +38,28 @@ enum lookup_type {
38
};
39
40
static int config_path_cmp(const void *unused_cmp_data,
41
- const void *entry,
42
- const void *entry_or_key,
41
+ const struct hashmap_entry *eptr,
42
+ const struct hashmap_entry *entry_or_key,
43
const void *unused_keydata)
44
{
45
- const struct submodule_entry *a = entry;
46
- const struct submodule_entry *b = entry_or_key;
45
+ const struct submodule_entry *a, *b;
46
+
47
+ a = container_of(eptr, const struct submodule_entry, ent);
48
+ b = container_of(entry_or_key, const struct submodule_entry, ent);
49
50
return strcmp(a->config->path, b->config->path) ||
51
!oideq(&a->config->gitmodules_oid, &b->config->gitmodules_oid);
52
}
53
54
static int config_name_cmp(const void *unused_cmp_data,
53
- const void *entry,
54
- const void *entry_or_key,
55
+ const struct hashmap_entry *eptr,
56
+ const struct hashmap_entry *entry_or_key,
57
const void *unused_keydata)
58
{
57
- const struct submodule_entry *a = entry;
58
- const struct submodule_entry *b = entry_or_key;
59
+ const struct submodule_entry *a, *b;
60
+
61
+ a = container_of(eptr, const struct submodule_entry, ent);
62
+ b = container_of(entry_or_key, const struct submodule_entry, ent);
63
64
return strcmp(a->config->name, b->config->name) ||
65
!oideq(&a->config->gitmodules_oid, &b->config->gitmodules_oid);
t/helper/test-hashmap.c
+6
-4
@@ -16,15 +16,17 @@ static const char *get_value(const struct test_entry *e)
16
}
17
18
static int test_entry_cmp(const void *cmp_data,
19
- const void *entry,
20
- const void *entry_or_key,
19
+ const struct hashmap_entry *eptr,
20
+ const struct hashmap_entry *entry_or_key,
21
const void *keydata)
22
{
23
const int ignore_case = cmp_data ? *((int *)cmp_data) : 0;
24
- const struct test_entry *e1 = entry;
25
- const struct test_entry *e2 = entry_or_key;
24
+ const struct test_entry *e1, *e2;
25
const char *key = keydata;
26
27
+ e1 = container_of(eptr, const struct test_entry, ent);
28
+ e2 = container_of(entry_or_key, const struct test_entry, ent);
29
+
30
if (ignore_case)
31
return strcasecmp(e1->key, key ? key : e2->key);
32
else