Skip to content

Commit f2f5ec8

Browse files
committed
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.
1 parent 852bc9f commit f2f5ec8

File tree

8 files changed

+54
-43
lines changed

8 files changed

+54
-43
lines changed

src/idxmap.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
#include "idxmap.h"
99

10+
#define kmalloc git__malloc
11+
#define kcalloc git__calloc
12+
#define krealloc git__realloc
13+
#define kreallocarray git__reallocarray
14+
#define kfree git__free
15+
#include "khash.h"
16+
17+
__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
18+
__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
19+
1020
/* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */
1121
static kh_inline khint_t idxentry_hash(const git_index_entry *e)
1222
{
@@ -104,11 +114,21 @@ void git_idxmap_free(git_idxmap *map)
104114
kh_destroy(idx, map);
105115
}
106116

117+
void git_idxmap_icase_free(git_idxmap_icase *map)
118+
{
119+
kh_destroy(idxicase, map);
120+
}
121+
107122
void git_idxmap_clear(git_idxmap *map)
108123
{
109124
kh_clear(idx, map);
110125
}
111126

127+
void git_idxmap_icase_clear(git_idxmap_icase *map)
128+
{
129+
kh_clear(idxicase, map);
130+
}
131+
112132
void git_idxmap_delete_at(git_idxmap *map, size_t idx)
113133
{
114134
kh_del(idx, map, idx);

src/idxmap.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,10 @@
99

1010
#include "common.h"
1111

12-
#include <ctype.h>
1312
#include "git2/index.h"
1413

15-
#define kmalloc git__malloc
16-
#define kcalloc git__calloc
17-
#define krealloc git__realloc
18-
#define kreallocarray git__reallocarray
19-
#define kfree git__free
20-
#include "khash.h"
21-
22-
__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
23-
__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
24-
25-
typedef khash_t(idx) git_idxmap;
26-
typedef khash_t(idxicase) git_idxmap_icase;
27-
28-
typedef khiter_t git_idxmap_iter;
14+
typedef struct kh_idx_s git_idxmap;
15+
typedef struct kh_idxicase_s git_idxmap_icase;
2916

3017
int git_idxmap_alloc(git_idxmap **map);
3118
int git_idxmap_icase_alloc(git_idxmap_icase **map);
@@ -41,7 +28,9 @@ int git_idxmap_has_data(git_idxmap *map, size_t idx);
4128
void git_idxmap_resize(git_idxmap *map, size_t size);
4229
void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size);
4330
void git_idxmap_free(git_idxmap *map);
31+
void git_idxmap_icase_free(git_idxmap_icase *map);
4432
void git_idxmap_clear(git_idxmap *map);
33+
void git_idxmap_icase_clear(git_idxmap_icase *map);
4534

4635
void git_idxmap_delete_at(git_idxmap *map, size_t idx);
4736
void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);

src/offmap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
#include "offmap.h"
99

10+
#define kmalloc git__malloc
11+
#define kcalloc git__calloc
12+
#define krealloc git__realloc
13+
#define kreallocarray git__reallocarray
14+
#define kfree git__free
15+
#include "khash.h"
16+
17+
__KHASH_TYPE(off, git_off_t, void *)
18+
1019
__KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
1120

1221
git_offmap *git_offmap_alloc(void)

src/offmap.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@
1111

1212
#include "git2/types.h"
1313

14-
#define kmalloc git__malloc
15-
#define kcalloc git__calloc
16-
#define krealloc git__realloc
17-
#define kreallocarray git__reallocarray
18-
#define kfree git__free
19-
#include "khash.h"
20-
21-
__KHASH_TYPE(off, git_off_t, void *)
22-
typedef khash_t(off) git_offmap;
14+
typedef struct kh_off_s git_offmap;
2315

2416
git_offmap *git_offmap_alloc(void);
2517
void git_offmap_free(git_offmap *map);

src/oidmap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
#include "oidmap.h"
99

10+
#define kmalloc git__malloc
11+
#define kcalloc git__calloc
12+
#define krealloc git__realloc
13+
#define kreallocarray git__reallocarray
14+
#define kfree git__free
15+
#include "khash.h"
16+
17+
__KHASH_TYPE(oid, const git_oid *, void *)
18+
1019
GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
1120
{
1221
khint_t h;

src/oidmap.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@
1111

1212
#include "git2/oid.h"
1313

14-
#define kmalloc git__malloc
15-
#define kcalloc git__calloc
16-
#define krealloc git__realloc
17-
#define kreallocarray git__reallocarray
18-
#define kfree git__free
19-
#include "khash.h"
20-
21-
__KHASH_TYPE(oid, const git_oid *, void *)
22-
typedef khash_t(oid) git_oidmap;
14+
typedef struct kh_oid_s git_oidmap;
2315

2416
git_oidmap *git_oidmap_alloc(void);
2517
void git_oidmap_free(git_oidmap *map);

src/strmap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
#include "strmap.h"
99

10+
#define kmalloc git__malloc
11+
#define kcalloc git__calloc
12+
#define krealloc git__realloc
13+
#define kreallocarray git__reallocarray
14+
#define kfree git__free
15+
#include "khash.h"
16+
17+
__KHASH_TYPE(str, const char *, void *)
18+
1019
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
1120

1221
int git_strmap_alloc(git_strmap **map)

src/strmap.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@
99

1010
#include "common.h"
1111

12-
#define kmalloc git__malloc
13-
#define kcalloc git__calloc
14-
#define krealloc git__realloc
15-
#define kreallocarray git__reallocarray
16-
#define kfree git__free
17-
#include "khash.h"
18-
19-
__KHASH_TYPE(str, const char *, void *)
20-
typedef khash_t(str) git_strmap;
21-
typedef khiter_t git_strmap_iter;
12+
typedef struct kh_str_s git_strmap;
2213

2314
int git_strmap_alloc(git_strmap **map);
2415
void git_strmap_free(git_strmap *map);

0 commit comments

Comments
 (0)