Commit 382b668bf2019eb8fb7c0afc4d6e3132dca9510e

Patrick Steinhardt 2018-11-23T18:38:18

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.

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,