line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* Copyright (C) the libgit2 contributors. All rights reserved. |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with |
5
|
|
|
|
|
|
|
* a Linking Exception. For full terms see the included COPYING file. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "strmap.h" |
9
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
19
|
156551
|
50
|
|
|
|
|
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
2704
|
|
|
|
|
|
int git_strmap_new(git_strmap **out) |
22
|
|
|
|
|
|
|
{ |
23
|
2704
|
|
|
|
|
|
*out = kh_init(str); |
24
|
2704
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(*out); |
25
|
|
|
|
|
|
|
|
26
|
2704
|
|
|
|
|
|
return 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
2614
|
|
|
|
|
|
void git_strmap_free(git_strmap *map) |
30
|
|
|
|
|
|
|
{ |
31
|
2614
|
|
|
|
|
|
kh_destroy(str, map); |
32
|
2614
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
510
|
|
|
|
|
|
void git_strmap_clear(git_strmap *map) |
35
|
|
|
|
|
|
|
{ |
36
|
510
|
|
|
|
|
|
kh_clear(str, map); |
37
|
510
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
101
|
|
|
|
|
|
size_t git_strmap_size(git_strmap *map) |
40
|
|
|
|
|
|
|
{ |
41
|
101
|
|
|
|
|
|
return kh_size(map); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
29983
|
|
|
|
|
|
void *git_strmap_get(git_strmap *map, const char *key) |
45
|
|
|
|
|
|
|
{ |
46
|
29983
|
|
|
|
|
|
size_t idx = kh_get(str, map, key); |
47
|
29983
|
100
|
|
|
|
|
if (idx == kh_end(map) || !kh_exist(map, idx)) |
|
|
50
|
|
|
|
|
|
48
|
21418
|
|
|
|
|
|
return NULL; |
49
|
8565
|
|
|
|
|
|
return kh_val(map, idx); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
16976
|
|
|
|
|
|
int git_strmap_set(git_strmap *map, const char *key, void *value) |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
size_t idx; |
55
|
|
|
|
|
|
|
int rval; |
56
|
|
|
|
|
|
|
|
57
|
16976
|
|
|
|
|
|
idx = kh_put(str, map, key, &rval); |
58
|
16976
|
50
|
|
|
|
|
if (rval < 0) |
59
|
0
|
|
|
|
|
|
return -1; |
60
|
|
|
|
|
|
|
|
61
|
16976
|
50
|
|
|
|
|
if (rval == 0) |
62
|
0
|
|
|
|
|
|
kh_key(map, idx) = key; |
63
|
|
|
|
|
|
|
|
64
|
16976
|
|
|
|
|
|
kh_val(map, idx) = value; |
65
|
|
|
|
|
|
|
|
66
|
16976
|
|
|
|
|
|
return 0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
6
|
|
|
|
|
|
int git_strmap_delete(git_strmap *map, const char *key) |
70
|
|
|
|
|
|
|
{ |
71
|
6
|
|
|
|
|
|
khiter_t idx = kh_get(str, map, key); |
72
|
6
|
50
|
|
|
|
|
if (idx == kh_end(map)) |
73
|
0
|
|
|
|
|
|
return GIT_ENOTFOUND; |
74
|
6
|
|
|
|
|
|
kh_del(str, map, idx); |
75
|
6
|
|
|
|
|
|
return 0; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
|
int git_strmap_exists(git_strmap *map, const char *key) |
79
|
|
|
|
|
|
|
{ |
80
|
3
|
|
|
|
|
|
return kh_get(str, map, key) != kh_end(map); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
19750
|
|
|
|
|
|
int git_strmap_iterate(void **value, git_strmap *map, size_t *iter, const char **key) |
84
|
|
|
|
|
|
|
{ |
85
|
19750
|
|
|
|
|
|
size_t i = *iter; |
86
|
|
|
|
|
|
|
|
87
|
37478
|
100
|
|
|
|
|
while (i < map->n_buckets && !kh_exist(map, i)) |
|
|
100
|
|
|
|
|
|
88
|
17728
|
|
|
|
|
|
i++; |
89
|
|
|
|
|
|
|
|
90
|
19750
|
100
|
|
|
|
|
if (i >= map->n_buckets) |
91
|
2578
|
|
|
|
|
|
return GIT_ITEROVER; |
92
|
|
|
|
|
|
|
|
93
|
17172
|
50
|
|
|
|
|
if (key) |
94
|
0
|
|
|
|
|
|
*key = kh_key(map, i); |
95
|
17172
|
50
|
|
|
|
|
if (value) |
96
|
17172
|
|
|
|
|
|
*value = kh_val(map, i); |
97
|
17172
|
|
|
|
|
|
*iter = ++i; |
98
|
|
|
|
|
|
|
|
99
|
17172
|
|
|
|
|
|
return 0; |
100
|
|
|
|
|
|
|
} |