Skip to content

Commit 8389855

Browse files
ttaylorrgitster
authored andcommitted
pack-revindex: remove unused 'find_revindex_position()'
Now that all 'find_revindex_position()' callers have been removed (and converted to the more descriptive 'offset_to_pack_pos()'), it is almost safe to get rid of 'find_revindex_position()' entirely. Almost, except for the fact that 'offset_to_pack_pos()' calls 'find_revindex_position()'. Inline 'find_revindex_position()' into 'offset_to_pack_pos()', and then remove 'find_revindex_position()' entirely. This is a straightforward refactoring with one minor snag. 'offset_to_pack_pos()' used to load the index before calling 'find_revindex_position()'. That means that by the time 'find_revindex_position()' starts executing, 'p->num_objects' can be safely read. After inlining, be careful to not read 'p->num_objects' until _after_ 'load_pack_revindex()' (which loads the index as a side-effect) has been called. Another small fix that is included is converting the upper- and lower-bounds to be unsigned's instead of ints. This dates back to 92e5c77 (revindex: export new APIs, 2013-10-24)--ironically, the last time we introduced new APIs here--but this unifies the types. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c3855f commit 8389855

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

pack-revindex.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,23 @@ int load_pack_revindex(struct packed_git *p)
169169
return 0;
170170
}
171171

172-
int find_revindex_position(struct packed_git *p, off_t ofs)
172+
int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
173173
{
174-
int lo = 0;
175-
int hi = p->num_objects + 1;
176-
const struct revindex_entry *revindex = p->revindex;
174+
unsigned lo, hi;
175+
const struct revindex_entry *revindex;
176+
177+
if (load_pack_revindex(p) < 0)
178+
return -1;
179+
180+
lo = 0;
181+
hi = p->num_objects + 1;
182+
revindex = p->revindex;
177183

178184
do {
179185
const unsigned mi = lo + (hi - lo) / 2;
180186
if (revindex[mi].offset == ofs) {
181-
return mi;
187+
*pos = mi;
188+
return 0;
182189
} else if (ofs < revindex[mi].offset)
183190
hi = mi;
184191
else
@@ -189,20 +196,6 @@ int find_revindex_position(struct packed_git *p, off_t ofs)
189196
return -1;
190197
}
191198

192-
int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
193-
{
194-
int ret;
195-
196-
if (load_pack_revindex(p) < 0)
197-
return -1;
198-
199-
ret = find_revindex_position(p, ofs);
200-
if (ret < 0)
201-
return ret;
202-
*pos = ret;
203-
return 0;
204-
}
205-
206199
uint32_t pack_pos_to_index(struct packed_git *p, uint32_t pos)
207200
{
208201
if (!p->revindex)

pack-revindex.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct revindex_entry {
2828
* given pack, returning zero on success and a negative value otherwise.
2929
*/
3030
int load_pack_revindex(struct packed_git *p);
31-
int find_revindex_position(struct packed_git *p, off_t ofs);
3231

3332
/*
3433
* offset_to_pack_pos converts an object offset to a pack position. This

0 commit comments

Comments
 (0)