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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Sep 29, 2016 at 17:29 UTC
76dd98c13947bd811c1d11d0c63ccdc9a4fb3142
3 files changed
+23
-8
builtin/fmt-merge-msg.c
+4
-6
@@ -314,12 +314,10 @@ static void add_people_info(struct strbuf *out,
314
struct string_list *authors,
315
struct string_list *committers)
316
{
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);
321
322
credit_people(out, authors, 'a');
323
credit_people(out, committers, 'c');
contrib/coccinelle/qsort.cocci
+18
@@ -17,3 +17,21 @@ expression nmemb, compar;
17
@@
18
- qsort(base, nmemb, sizeof(T), compar);
19
+ 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
@@ -230,8 +230,7 @@ cmp_string (const void *pstr1, const void *pstr2)
230
static inline void
231
string_list_sort (string_list_ty *slp)
232
{
233
- if (slp->nitems > 0)
234
- QSORT(slp->item, slp->nitems, cmp_string);
233
+ QSORT(slp->item, slp->nitems, cmp_string);
234
}
235
236
/* Test whether a sorted string list contains a given string. */