summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-11-23 18:38:18 +0100
committerPatrick Steinhardt <ps@pks.im>2018-11-28 15:22:27 +0100
commit382b668bf2019eb8fb7c0afc4d6e3132dca9510e (patch)
treebbf4314f4ec75a09f87845814e047e3394f03fae
parentae765d0013e767e0c3824eea439a606b81f3083a (diff)
downloadlibgit2-382b668bf2019eb8fb7c0afc4d6e3132dca9510e.tar.gz
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.
-rw-r--r--src/offmap.c11
-rw-r--r--src/offmap.h3
-rw-r--r--src/oidmap.c11
-rw-r--r--src/oidmap.h6
-rw-r--r--src/strmap.c11
-rw-r--r--src/strmap.h4
6 files changed, 41 insertions, 5 deletions
diff --git a/src/offmap.c b/src/offmap.c
index ab6649697..2ab485589 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 0b0896b8f..bf2b13de4 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 5f156a18e..a2051f892 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 49f129e93..8f6016af9 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 de6826d03..d9d89aa1b 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 802b92494..6d999e141 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,