Skip to content

Commit 382b668

Browse files
committed
khash: implement begin/end via functions instead of macros
Right now, the `git_*map_begin()` and `git_*map_end()` helpers are implemented via macros which simply redirect to `kh_begin` and `kh_end`. As these macros refer to members of the map structures, they make it impossible to move the khash include into the implementation files. Implement these helpers as real functions instead to further decouple the headers from implementations.
1 parent ae765d0 commit 382b668

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

src/offmap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,14 @@ void git_offmap_delete(git_offmap *map, const git_off_t key)
8181
if (git_offmap_valid_index(map, idx))
8282
git_offmap_delete_at(map, idx);
8383
}
84+
85+
size_t git_offmap_begin(git_offmap *map)
86+
{
87+
GIT_UNUSED(map);
88+
return 0;
89+
}
90+
91+
size_t git_offmap_end(git_offmap *map)
92+
{
93+
return map->n_buckets;
94+
}

src/offmap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ int git_offmap_put(git_offmap *map, const git_off_t key, int *err);
4040
void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval);
4141
void git_offmap_delete(git_offmap *map, const git_off_t key);
4242

43+
size_t git_offmap_begin(git_offmap *map);
44+
size_t git_offmap_end(git_offmap *map);
45+
4346
#define git_offmap_foreach kh_foreach
4447
#define git_offmap_foreach_value kh_foreach_value
4548

src/oidmap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,14 @@ void git_oidmap_delete(git_oidmap *map, const git_oid *key)
103103
if (git_oidmap_valid_index(map, idx))
104104
git_oidmap_delete_at(map, idx);
105105
}
106+
107+
size_t git_oidmap_begin(git_oidmap *map)
108+
{
109+
GIT_UNUSED(map);
110+
return 0;
111+
}
112+
113+
size_t git_oidmap_end(git_oidmap *map)
114+
{
115+
return map->n_buckets;
116+
}

src/oidmap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err);
4343
void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval);
4444
void git_oidmap_delete(git_oidmap *map, const git_oid *key);
4545

46-
#define git_oidmap_foreach_value kh_foreach_value
46+
size_t git_oidmap_begin(git_oidmap *map);
47+
size_t git_oidmap_end(git_oidmap *map);
4748

48-
#define git_oidmap_begin kh_begin
49-
#define git_oidmap_end kh_end
49+
#define git_oidmap_foreach_value kh_foreach_value
5050

5151
#endif

src/strmap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ void git_strmap_delete(git_strmap *map, const char *key)
102102
git_strmap_delete_at(map, idx);
103103
}
104104

105+
size_t git_strmap_begin(git_strmap *map)
106+
{
107+
GIT_UNUSED(map);
108+
return 0;
109+
}
110+
111+
size_t git_strmap_end(git_strmap *map)
112+
{
113+
return map->n_buckets;
114+
}
115+
105116
int git_strmap_next(
106117
void **data,
107118
git_strmap_iter* iter,

src/strmap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void git_strmap_delete(git_strmap *map, const char *key);
4545
#define git_strmap_foreach kh_foreach
4646
#define git_strmap_foreach_value kh_foreach_value
4747

48-
#define git_strmap_begin kh_begin
49-
#define git_strmap_end kh_end
48+
size_t git_strmap_begin(git_strmap *map);
49+
size_t git_strmap_end(git_strmap *map);
5050

5151
int git_strmap_next(
5252
void **data,

0 commit comments

Comments
 (0)