OFFSETOF_VAR macro to simplify hashmap iterators
While we cannot rely on a `__typeof__' operator being portable to use with `offsetof'; we can calculate the pointer offset using an existing pointer and the address of a member using pointer arithmetic for compilers without `__typeof__'. This allows us to simplify usage of hashmap iterator macros by not having to specify a type when a pointer of that type is already given. In the future, list iterator macros (e.g. list_for_each_entry) may also be implemented using OFFSETOF_VAR to save hackers the trouble of using container_of/list_entry macros and without relying on non-portable `__typeof__'. v3: use `__typeof__' to avoid clang warnings Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
c8e424c9c9
commit
23dee69f53
@ -2136,7 +2136,6 @@ static void handle_directory_level_conflicts(struct merge_options *opt,
|
||||
struct string_list remove_from_merge = STRING_LIST_INIT_NODUP;
|
||||
|
||||
hashmap_for_each_entry(dir_re_head, &iter, head_ent,
|
||||
struct dir_rename_entry,
|
||||
ent /* member name */) {
|
||||
merge_ent = dir_rename_find_entry(dir_re_merge, head_ent->dir);
|
||||
if (merge_ent &&
|
||||
@ -2162,7 +2161,6 @@ static void handle_directory_level_conflicts(struct merge_options *opt,
|
||||
remove_hashmap_entries(dir_re_merge, &remove_from_merge);
|
||||
|
||||
hashmap_for_each_entry(dir_re_merge, &iter, merge_ent,
|
||||
struct dir_rename_entry,
|
||||
ent /* member name */) {
|
||||
head_ent = dir_rename_find_entry(dir_re_head, merge_ent->dir);
|
||||
if (tree_has_path(opt->repo, merge, merge_ent->dir)) {
|
||||
@ -2268,7 +2266,6 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs)
|
||||
* that there is no winner), we no longer need possible_new_dirs.
|
||||
*/
|
||||
hashmap_for_each_entry(dir_renames, &iter, entry,
|
||||
struct dir_rename_entry,
|
||||
ent /* member name */) {
|
||||
int max = 0;
|
||||
int bad_max = 0;
|
||||
@ -2628,7 +2625,6 @@ static struct string_list *get_renames(struct merge_options *opt,
|
||||
}
|
||||
|
||||
hashmap_for_each_entry(&collisions, &iter, e,
|
||||
struct collision_entry,
|
||||
ent /* member name */) {
|
||||
free(e->target_file);
|
||||
string_list_clear(&e->source_files, 0);
|
||||
@ -2847,7 +2843,6 @@ static void initial_cleanup_rename(struct diff_queue_struct *pairs,
|
||||
struct dir_rename_entry *e;
|
||||
|
||||
hashmap_for_each_entry(dir_renames, &iter, e,
|
||||
struct dir_rename_entry,
|
||||
ent /* member name */) {
|
||||
free(e->dir);
|
||||
strbuf_release(&e->new_dir);
|
||||
|
||||
Reference in New Issue
Block a user