Skip to content

Commit 76dd98c

Browse files
rscharfegitster
authored andcommitted
remove unnecessary check before QSORT
Add a semantic patch for removing checks similar to the one that QSORT already does internally and apply it to the code base. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ed0d8d commit 76dd98c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

builtin/fmt-merge-msg.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,10 @@ static void add_people_info(struct strbuf *out,
314314
struct string_list *authors,
315315
struct string_list *committers)
316316
{
317-
if (authors->nr)
318-
QSORT(authors->items, authors->nr,
319-
cmp_string_list_util_as_integral);
320-
if (committers->nr)
321-
QSORT(committers->items, committers->nr,
322-
cmp_string_list_util_as_integral);
317+
QSORT(authors->items, authors->nr,
318+
cmp_string_list_util_as_integral);
319+
QSORT(committers->items, committers->nr,
320+
cmp_string_list_util_as_integral);
323321

324322
credit_people(out, authors, 'a');
325323
credit_people(out, committers, 'c');

contrib/coccinelle/qsort.cocci

+18
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ expression nmemb, compar;
1717
@@
1818
- qsort(base, nmemb, sizeof(T), compar);
1919
+ QSORT(base, nmemb, compar);
20+
21+
@@
22+
expression base, nmemb, compar;
23+
@@
24+
- if (nmemb)
25+
QSORT(base, nmemb, compar);
26+
27+
@@
28+
expression base, nmemb, compar;
29+
@@
30+
- if (nmemb > 0)
31+
QSORT(base, nmemb, compar);
32+
33+
@@
34+
expression base, nmemb, compar;
35+
@@
36+
- if (nmemb > 1)
37+
QSORT(base, nmemb, compar);

sh-i18n--envsubst.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ cmp_string (const void *pstr1, const void *pstr2)
230230
static inline void
231231
string_list_sort (string_list_ty *slp)
232232
{
233-
if (slp->nitems > 0)
234-
QSORT(slp->item, slp->nitems, cmp_string);
233+
QSORT(slp->item, slp->nitems, cmp_string);
235234
}
236235

237236
/* Test whether a sorted string list contains a given string. */

0 commit comments

Comments
 (0)