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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/src/offmap.c b/src/offmap.c
index ab66496..2ab4855 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -81,3 +81,14 @@ void git_offmap_delete(git_offmap *map, const git_off_t key)
if (git_offmap_valid_index(map, idx))
git_offmap_delete_at(map, idx);
}
+
+size_t git_offmap_begin(git_offmap *map)
+{
+ GIT_UNUSED(map);
+ return 0;
+}
+
+size_t git_offmap_end(git_offmap *map)
+{
+ return map->n_buckets;
+}
diff --git a/src/offmap.h b/src/offmap.h
index 0b0896b..bf2b13d 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -40,6 +40,9 @@ int git_offmap_put(git_offmap *map, const git_off_t key, int *err);
void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval);
void git_offmap_delete(git_offmap *map, const git_off_t key);
+size_t git_offmap_begin(git_offmap *map);
+size_t git_offmap_end(git_offmap *map);
+
#define git_offmap_foreach kh_foreach
#define git_offmap_foreach_value kh_foreach_value
diff --git a/src/oidmap.c b/src/oidmap.c
index 5f156a1..a2051f8 100644
--- a/src/oidmap.c
+++ b/src/oidmap.c
@@ -103,3 +103,14 @@ void git_oidmap_delete(git_oidmap *map, const git_oid *key)
if (git_oidmap_valid_index(map, idx))
git_oidmap_delete_at(map, idx);
}
+
+size_t git_oidmap_begin(git_oidmap *map)
+{
+ GIT_UNUSED(map);
+ return 0;
+}
+
+size_t git_oidmap_end(git_oidmap *map)
+{
+ return map->n_buckets;
+}
diff --git a/src/oidmap.h b/src/oidmap.h
index 49f129e..8f6016a 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -43,9 +43,9 @@ int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err);
void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval);
void git_oidmap_delete(git_oidmap *map, const git_oid *key);
-#define git_oidmap_foreach_value kh_foreach_value
+size_t git_oidmap_begin(git_oidmap *map);
+size_t git_oidmap_end(git_oidmap *map);
-#define git_oidmap_begin kh_begin
-#define git_oidmap_end kh_end
+#define git_oidmap_foreach_value kh_foreach_value
#endif
diff --git a/src/strmap.c b/src/strmap.c
index de6826d..d9d89aa 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -102,6 +102,17 @@ void git_strmap_delete(git_strmap *map, const char *key)
git_strmap_delete_at(map, idx);
}
+size_t git_strmap_begin(git_strmap *map)
+{
+ GIT_UNUSED(map);
+ return 0;
+}
+
+size_t git_strmap_end(git_strmap *map)
+{
+ return map->n_buckets;
+}
+
int git_strmap_next(
void **data,
git_strmap_iter* iter,
diff --git a/src/strmap.h b/src/strmap.h
index 802b924..6d999e1 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -45,8 +45,8 @@ void git_strmap_delete(git_strmap *map, const char *key);
#define git_strmap_foreach kh_foreach
#define git_strmap_foreach_value kh_foreach_value
-#define git_strmap_begin kh_begin
-#define git_strmap_end kh_end
+size_t git_strmap_begin(git_strmap *map);
+size_t git_strmap_end(git_strmap *map);
int git_strmap_next(
void **data,