Skip to content

Commit bd66925

Browse files
committed
oidmap: remove legacy low-level interface
Remove the low-level interface that was exposing implementation details of `git_oidmap` to callers. From now on, only the high-level functions shall be used to retrieve or modify values of a map. Adjust remaining existing callers.
1 parent 4713e7c commit bd66925

File tree

3 files changed

+71
-257
lines changed

3 files changed

+71
-257
lines changed

src/oidmap.c

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ size_t git_oidmap_size(git_oidmap *map)
5050

5151
void *git_oidmap_get(git_oidmap *map, const git_oid *key)
5252
{
53-
size_t idx = git_oidmap_lookup_index(map, key);
54-
if (!git_oidmap_valid_index(map, idx) ||
55-
!git_oidmap_has_data(map, idx))
53+
size_t idx = kh_get(oid, map, key);
54+
if (idx == kh_end(map) || !kh_exist(map, idx))
5655
return NULL;
5756
return kh_val(map, idx);
5857
}
@@ -76,10 +75,10 @@ int git_oidmap_set(git_oidmap *map, const git_oid *key, void *value)
7675

7776
int git_oidmap_delete(git_oidmap *map, const git_oid *key)
7877
{
79-
khiter_t idx = git_oidmap_lookup_index(map, key);
80-
if (!git_oidmap_valid_index(map, idx))
78+
khiter_t idx = kh_get(oid, map, key);
79+
if (idx == kh_end(map))
8180
return GIT_ENOTFOUND;
82-
git_oidmap_delete_at(map, idx);
81+
kh_del(oid, map, idx);
8382
return 0;
8483
}
8584

@@ -92,84 +91,17 @@ int git_oidmap_iterate(void **value, git_oidmap *map, size_t *iter, const git_oi
9291
{
9392
size_t i = *iter;
9493

95-
while (i < git_oidmap_end(map) && !git_oidmap_has_data(map, i))
94+
while (i < map->n_buckets && !kh_exist(map, i))
9695
i++;
9796

98-
if (i >= git_oidmap_end(map))
97+
if (i >= map->n_buckets)
9998
return GIT_ITEROVER;
10099

101100
if (key)
102-
*key = git_oidmap_key(map, i);
101+
*key = kh_key(map, i);
103102
if (value)
104-
*value = git_oidmap_value_at(map, i);
103+
*value = kh_value(map, i);
105104
*iter = ++i;
106105

107106
return 0;
108107
}
109-
110-
size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key)
111-
{
112-
return kh_get(oid, map, key);
113-
}
114-
115-
int git_oidmap_valid_index(git_oidmap *map, size_t idx)
116-
{
117-
return idx != kh_end(map);
118-
}
119-
120-
int git_oidmap_has_data(git_oidmap *map, size_t idx)
121-
{
122-
return kh_exist(map, idx);
123-
}
124-
125-
const git_oid *git_oidmap_key(git_oidmap *map, size_t idx)
126-
{
127-
return kh_key(map, idx);
128-
}
129-
130-
void git_oidmap_set_key_at(git_oidmap *map, size_t idx, git_oid *key)
131-
{
132-
kh_key(map, idx) = key;
133-
}
134-
135-
void *git_oidmap_value_at(git_oidmap *map, size_t idx)
136-
{
137-
return kh_val(map, idx);
138-
}
139-
140-
void git_oidmap_set_value_at(git_oidmap *map, size_t idx, void *value)
141-
{
142-
kh_val(map, idx) = value;
143-
}
144-
145-
void git_oidmap_delete_at(git_oidmap *map, size_t idx)
146-
{
147-
kh_del(oid, map, idx);
148-
}
149-
150-
int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err)
151-
{
152-
return kh_put(oid, map, key, err);
153-
}
154-
155-
void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval)
156-
{
157-
khiter_t idx = kh_put(oid, map, key, rval);
158-
159-
if ((*rval) >= 0) {
160-
if ((*rval) == 0)
161-
kh_key(map, idx) = key;
162-
kh_val(map, idx) = value;
163-
}
164-
}
165-
166-
size_t git_oidmap_begin(git_oidmap *map)
167-
{
168-
GIT_UNUSED(map);
169-
return 0;
170-
}
171-
172-
size_t git_oidmap_end(git_oidmap *map)
173-
{
174-
return map->n_buckets;
175-
}

src/oidmap.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,6 @@ int git_oidmap_exists(git_oidmap *map, const git_oid *key);
120120
*/
121121
int git_oidmap_iterate(void **value, git_oidmap *map, size_t *iter, const git_oid **key);
122122

123-
size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key);
124-
int git_oidmap_valid_index(git_oidmap *map, size_t idx);
125-
126-
int git_oidmap_has_data(git_oidmap *map, size_t idx);
127-
128-
const git_oid *git_oidmap_key(git_oidmap *map, size_t idx);
129-
void git_oidmap_set_key_at(git_oidmap *map, size_t idx, git_oid *key);
130-
void *git_oidmap_value_at(git_oidmap *map, size_t idx);
131-
void git_oidmap_set_value_at(git_oidmap *map, size_t idx, void *value);
132-
void git_oidmap_delete_at(git_oidmap *map, size_t idx);
133-
134-
int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err);
135-
void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval);
136-
137-
size_t git_oidmap_begin(git_oidmap *map);
138-
size_t git_oidmap_end(git_oidmap *map);
139-
140123
#define git_oidmap_foreach_value(h, vvar, code) { size_t __i = 0; \
141124
while (git_oidmap_iterate((void **) &(vvar), h, &__i, NULL) == 0) { \
142125
code; \

0 commit comments

Comments
 (0)