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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jan 24, 2018 at 12:14 UTC
f34242975fae1468dd94d31289d27f68853a28fb
1 file changed
+6
-6
refs/packed-backend.c
+6
-6
@@ -927,7 +927,12 @@ static struct ref_iterator *packed_ref_iterator_begin(
927
*/
928
snapshot = get_snapshot(refs);
929
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)
936
return empty_ref_iterator_begin();
937
938
iter = xcalloc(1, sizeof(*iter));
@@ -937,11 +942,6 @@ static struct ref_iterator *packed_ref_iterator_begin(
942
iter->snapshot = snapshot;
943
acquire_snapshot(snapshot);
944
940
- if (prefix && *prefix)
941
- start = find_reference_location(snapshot, prefix, 0);
942
- else
943
- start = snapshot->start;
944
-
945
iter->pos = start;
946
iter->eof = snapshot->eof;
947
strbuf_init(&iter->refname_buf, 0);