Skip to content

Commit df42f36

Browse files
committed
idxmap: remove legacy low-level interface
Remove the low-level interface that was exposing implementation details of `git_idxmap` 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 bd66925 commit df42f36

File tree

2 files changed

+10
-71
lines changed

2 files changed

+10
-71
lines changed

src/idxmap.c

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ int git_idxmap_icase_resize(git_idxmap_icase *map, size_t size)
8888

8989
void *git_idxmap_get(git_idxmap *map, const git_index_entry *key)
9090
{
91-
size_t idx = git_idxmap_lookup_index(map, key);
92-
if (!git_idxmap_valid_index(map, idx) ||
93-
!git_idxmap_has_data(map, idx))
91+
size_t idx = kh_get(idx, map, key);
92+
if (idx == kh_end(map) || !kh_exist(map, idx))
9493
return NULL;
9594
return kh_val(map, idx);
9695
}
@@ -131,9 +130,8 @@ int git_idxmap_icase_set(git_idxmap_icase *map, const git_index_entry *key, void
131130

132131
void *git_idxmap_icase_get(git_idxmap_icase *map, const git_index_entry *key)
133132
{
134-
size_t idx = git_idxmap_icase_lookup_index(map, key);
135-
if (!git_idxmap_icase_valid_index(map, idx) ||
136-
!git_idxmap_icase_has_data(map, idx))
133+
size_t idx = kh_get(idxicase, map, key);
134+
if (idx == kh_end(map) || !kh_exist(map, idx))
137135
return NULL;
138136
return kh_val(map, idx);
139137
}
@@ -162,63 +160,18 @@ void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key,
162160

163161
int git_idxmap_delete(git_idxmap *map, const git_index_entry *key)
164162
{
165-
khiter_t idx = git_idxmap_lookup_index(map, key);
166-
if (!git_idxmap_valid_index(map, idx))
163+
khiter_t idx = kh_get(idx, map, key);
164+
if (idx == kh_end(map))
167165
return GIT_ENOTFOUND;
168-
git_idxmap_delete_at(map, idx);
166+
kh_del(idx, map, idx);
169167
return 0;
170168
}
171169

172170
int git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key)
173171
{
174-
khiter_t idx = git_idxmap_icase_lookup_index(map, key);
175-
if (!git_idxmap_valid_index((git_idxmap *)map, idx))
172+
khiter_t idx = kh_get(idxicase, map, key);
173+
if (idx == kh_end(map))
176174
return GIT_ENOTFOUND;
177-
git_idxmap_icase_delete_at(map, idx);
178-
return 0;
179-
}
180-
181-
size_t git_idxmap_lookup_index(git_idxmap *map, const git_index_entry *key)
182-
{
183-
return kh_get(idx, map, key);
184-
}
185-
186-
size_t git_idxmap_icase_lookup_index(git_idxmap_icase *map, const git_index_entry *key)
187-
{
188-
return kh_get(idxicase, map, key);
189-
}
190-
191-
void *git_idxmap_value_at(git_idxmap *map, size_t idx)
192-
{
193-
return kh_val(map, idx);
194-
}
195-
196-
int git_idxmap_valid_index(git_idxmap *map, size_t idx)
197-
{
198-
return idx != kh_end(map);
199-
}
200-
201-
int git_idxmap_icase_valid_index(git_idxmap_icase *map, size_t idx)
202-
{
203-
return idx != kh_end(map);
204-
}
205-
206-
int git_idxmap_has_data(git_idxmap *map, size_t idx)
207-
{
208-
return kh_exist(map, idx);
209-
}
210-
211-
int git_idxmap_icase_has_data(git_idxmap_icase *map, size_t idx)
212-
{
213-
return kh_exist(map, idx);
214-
}
215-
216-
void git_idxmap_delete_at(git_idxmap *map, size_t idx)
217-
{
218-
kh_del(idx, map, idx);
219-
}
220-
221-
void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx)
222-
{
223175
kh_del(idxicase, map, idx);
176+
return 0;
224177
}

src/idxmap.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,4 @@ int git_idxmap_delete(git_idxmap *map, const git_index_entry *key);
174174
*/
175175
int git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key);
176176

177-
void git_idxmap_insert(git_idxmap *map, const git_index_entry *key, void *value, int *rval);
178-
void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key, void *value, int *rval);
179-
180-
size_t git_idxmap_lookup_index(git_idxmap *map, const git_index_entry *key);
181-
size_t git_idxmap_icase_lookup_index(git_idxmap_icase *map, const git_index_entry *key);
182-
void *git_idxmap_value_at(git_idxmap *map, size_t idx);
183-
int git_idxmap_valid_index(git_idxmap *map, size_t idx);
184-
int git_idxmap_icase_valid_index(git_idxmap_icase *map, size_t idx);
185-
int git_idxmap_has_data(git_idxmap *map, size_t idx);
186-
int git_idxmap_icase_has_data(git_idxmap_icase *map, size_t idx);
187-
188-
void git_idxmap_delete_at(git_idxmap *map, size_t idx);
189-
void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
190-
191177
#endif

0 commit comments

Comments
 (0)