Skip to content

Commit f342429

Browse files
mhaggergitster
authored andcommitted
packed_ref_iterator_begin(): make optimization more general
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]>
1 parent 4a14f8d commit f342429

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

refs/packed-backend.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,12 @@ static struct ref_iterator *packed_ref_iterator_begin(
927927
*/
928928
snapshot = get_snapshot(refs);
929929

930-
if (!snapshot->buf)
930+
if (prefix && *prefix)
931+
start = find_reference_location(snapshot, prefix, 0);
932+
else
933+
start = snapshot->start;
934+
935+
if (start == snapshot->eof)
931936
return empty_ref_iterator_begin();
932937

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

940-
if (prefix && *prefix)
941-
start = find_reference_location(snapshot, prefix, 0);
942-
else
943-
start = snapshot->start;
944-
945945
iter->pos = start;
946946
iter->eof = snapshot->eof;
947947
strbuf_init(&iter->refname_buf, 0);

0 commit comments

Comments
 (0)