summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-11-23 19:27:09 +0100
committerPatrick Steinhardt <ps@pks.im>2018-11-28 15:22:27 +0100
commitf2f5ec844d96fe0007a47e4df00499ab5598b41f (patch)
tree2d9bee0c39dbd05ca1a7db13fd3d2583cd823406
parent852bc9f4967d3bd70a284794ff486253e37c6980 (diff)
downloadlibgit2-f2f5ec844d96fe0007a47e4df00499ab5598b41f.tar.gz
khash: move khash include into implementation files
The current map implementations directly include the "khash.h" headers into their own headers to make available a set of static functions, defines et cetera. Besides leaking the complete khash namespace into files wherever khashes are used, this also triggers Clang's -Wunused-function warnings when some of the static functions are not being used at all. Fix the issue by moving the includes into the respective map implementation files. Add forward declares for all the map types to make them known.
-rw-r--r--src/idxmap.c20
-rw-r--r--src/idxmap.h19
-rw-r--r--src/offmap.c9
-rw-r--r--src/offmap.h10
-rw-r--r--src/oidmap.c9
-rw-r--r--src/oidmap.h10
-rw-r--r--src/strmap.c9
-rw-r--r--src/strmap.h11
8 files changed, 54 insertions, 43 deletions
diff --git a/src/idxmap.c b/src/idxmap.c
index 45f0c2204..05a7b2feb 100644
--- a/src/idxmap.c
+++ b/src/idxmap.c
@@ -7,6 +7,16 @@
#include "idxmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
+__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
+
/* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */
static kh_inline khint_t idxentry_hash(const git_index_entry *e)
{
@@ -104,11 +114,21 @@ void git_idxmap_free(git_idxmap *map)
kh_destroy(idx, map);
}
+void git_idxmap_icase_free(git_idxmap_icase *map)
+{
+ kh_destroy(idxicase, map);
+}
+
void git_idxmap_clear(git_idxmap *map)
{
kh_clear(idx, map);
}
+void git_idxmap_icase_clear(git_idxmap_icase *map)
+{
+ kh_clear(idxicase, map);
+}
+
void git_idxmap_delete_at(git_idxmap *map, size_t idx)
{
kh_del(idx, map, idx);
diff --git a/src/idxmap.h b/src/idxmap.h
index 7fed8b9d2..215a24521 100644
--- a/src/idxmap.h
+++ b/src/idxmap.h
@@ -9,23 +9,10 @@
#include "common.h"
-#include <ctype.h>
#include "git2/index.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
-__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
-
-typedef khash_t(idx) git_idxmap;
-typedef khash_t(idxicase) git_idxmap_icase;
-
-typedef khiter_t git_idxmap_iter;
+typedef struct kh_idx_s git_idxmap;
+typedef struct kh_idxicase_s git_idxmap_icase;
int git_idxmap_alloc(git_idxmap **map);
int git_idxmap_icase_alloc(git_idxmap_icase **map);
@@ -41,7 +28,9 @@ int git_idxmap_has_data(git_idxmap *map, size_t idx);
void git_idxmap_resize(git_idxmap *map, size_t size);
void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size);
void git_idxmap_free(git_idxmap *map);
+void git_idxmap_icase_free(git_idxmap_icase *map);
void git_idxmap_clear(git_idxmap *map);
+void git_idxmap_icase_clear(git_idxmap_icase *map);
void git_idxmap_delete_at(git_idxmap *map, size_t idx);
void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
diff --git a/src/offmap.c b/src/offmap.c
index e6e5cfef5..d0fa9f031 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -7,6 +7,15 @@
#include "offmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(off, git_off_t, void *)
+
__KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
git_offmap *git_offmap_alloc(void)
diff --git a/src/offmap.h b/src/offmap.h
index 82ebfb780..c68809389 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -11,15 +11,7 @@
#include "git2/types.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(off, git_off_t, void *)
-typedef khash_t(off) git_offmap;
+typedef struct kh_off_s git_offmap;
git_offmap *git_offmap_alloc(void);
void git_offmap_free(git_offmap *map);
diff --git a/src/oidmap.c b/src/oidmap.c
index a2051f892..c42e5c25a 100644
--- a/src/oidmap.c
+++ b/src/oidmap.c
@@ -7,6 +7,15 @@
#include "oidmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(oid, const git_oid *, void *)
+
GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
{
khint_t h;
diff --git a/src/oidmap.h b/src/oidmap.h
index f34c03420..a417907bd 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -11,15 +11,7 @@
#include "git2/oid.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(oid, const git_oid *, void *)
-typedef khash_t(oid) git_oidmap;
+typedef struct kh_oid_s git_oidmap;
git_oidmap *git_oidmap_alloc(void);
void git_oidmap_free(git_oidmap *map);
diff --git a/src/strmap.c b/src/strmap.c
index 0c35357b7..cee7f69e5 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -7,6 +7,15 @@
#include "strmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(str, const char *, void *)
+
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
int git_strmap_alloc(git_strmap **map)
diff --git a/src/strmap.h b/src/strmap.h
index 785649465..2649acbfb 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -9,16 +9,7 @@
#include "common.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(str, const char *, void *)
-typedef khash_t(str) git_strmap;
-typedef khiter_t git_strmap_iter;
+typedef struct kh_str_s git_strmap;
int git_strmap_alloc(git_strmap **map);
void git_strmap_free(git_strmap *map);