Skip to content

Commit 7e65c75

Browse files
rscharfegitster
authored andcommitted
show-branch: use QSORT
Shorten the code by using QSORT instead of calling qsort(3) directly, as the former determines the element size automatically and checks if there are at least two elements to sort already. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b5294d commit 7e65c75

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

builtin/show-branch.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ static int compare_ref_name(const void *a_, const void *b_)
353353

354354
static void sort_ref_range(int bottom, int top)
355355
{
356-
qsort(ref_name + bottom, top - bottom, sizeof(ref_name[0]),
357-
compare_ref_name);
356+
QSORT(ref_name + bottom, top - bottom, compare_ref_name);
358357
}
359358

360359
static int append_ref(const char *refname, const struct object_id *oid,
@@ -540,8 +539,7 @@ static void append_one_rev(const char *av)
540539
if (saved_matches == ref_name_cnt &&
541540
ref_name_cnt < MAX_REVS)
542541
error(_("no matching refs with %s"), av);
543-
if (saved_matches + 1 < ref_name_cnt)
544-
sort_ref_range(saved_matches, ref_name_cnt);
542+
sort_ref_range(saved_matches, ref_name_cnt);
545543
return;
546544
}
547545
die("bad sha1 reference %s", av);

0 commit comments

Comments
 (0)