Skip to content

Commit

Permalink
packed_ref_iterator_begin(): make optimization more general
Browse files Browse the repository at this point in the history
We can return an empty iterator not only if the `packed-refs` file is
missing, but also if it is empty or if there are no references whose
names succeed `prefix`. Optimize away those cases as well by moving
the call to `find_reference_location()` higher in the function and
checking whether the determined start position is the same as
`snapshot->eof`. (This is possible now because the previous commit
made `find_reference_location()` robust against empty snapshots.)

Signed-off-by: Michael Haggerty <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
mhagger authored and gitster committed Jan 24, 2018
1 parent 4a14f8d commit f342429
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions refs/packed-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,12 @@ static struct ref_iterator *packed_ref_iterator_begin(
*/
snapshot = get_snapshot(refs);

if (!snapshot->buf)
if (prefix && *prefix)
start = find_reference_location(snapshot, prefix, 0);
else
start = snapshot->start;

if (start == snapshot->eof)
return empty_ref_iterator_begin();

iter = xcalloc(1, sizeof(*iter));
Expand All @@ -937,11 +942,6 @@ static struct ref_iterator *packed_ref_iterator_begin(
iter->snapshot = snapshot;
acquire_snapshot(snapshot);

if (prefix && *prefix)
start = find_reference_location(snapshot, prefix, 0);
else
start = snapshot->start;

iter->pos = start;
iter->eof = snapshot->eof;
strbuf_init(&iter->refname_buf, 0);
Expand Down

0 comments on commit f342429

Please sign in to comment.