]> granicus.if.org Git - git/commitdiff
remove unnecessary check before QSORT
authorRené Scharfe <l.s.r@web.de>
Thu, 29 Sep 2016 15:29:29 +0000 (17:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 22:42:18 +0000 (15:42 -0700)
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>
builtin/fmt-merge-msg.c
contrib/coccinelle/qsort.cocci
sh-i18n--envsubst.c

index 4976967a96402e8fe9a09fb5ce2057a436153a5e..efab62fd85e314ccb6ec5becedead91823d03dde 100644 (file)
@@ -314,12 +314,10 @@ static void add_people_info(struct strbuf *out,
                            struct string_list *authors,
                            struct string_list *committers)
 {
-       if (authors->nr)
-               QSORT(authors->items, authors->nr,
-                     cmp_string_list_util_as_integral);
-       if (committers->nr)
-               QSORT(committers->items, committers->nr,
-                     cmp_string_list_util_as_integral);
+       QSORT(authors->items, authors->nr,
+             cmp_string_list_util_as_integral);
+       QSORT(committers->items, committers->nr,
+             cmp_string_list_util_as_integral);
 
        credit_people(out, authors, 'a');
        credit_people(out, committers, 'c');
index a094e7c5e7f060f68f452279479111fcaf08b1df..22b93a99664d2745aa74c6566be0225f6842e882 100644 (file)
@@ -17,3 +17,21 @@ expression nmemb, compar;
 @@
 - qsort(base, nmemb, sizeof(T), compar);
 + QSORT(base, nmemb, compar);
+
+@@
+expression base, nmemb, compar;
+@@
+- if (nmemb)
+    QSORT(base, nmemb, compar);
+
+@@
+expression base, nmemb, compar;
+@@
+- if (nmemb > 0)
+    QSORT(base, nmemb, compar);
+
+@@
+expression base, nmemb, compar;
+@@
+- if (nmemb > 1)
+    QSORT(base, nmemb, compar);
index 3637a2a64b28789c31d1be41e150d658a9d47e6e..c3a2b5ad17c74613811a0ce850586fa1b9e099bd 100644 (file)
@@ -230,8 +230,7 @@ cmp_string (const void *pstr1, const void *pstr2)
 static inline void
 string_list_sort (string_list_ty *slp)
 {
-  if (slp->nitems > 0)
-    QSORT(slp->item, slp->nitems, cmp_string);
+  QSORT(slp->item, slp->nitems, cmp_string);
 }
 
 /* Test whether a sorted string list contains a given string.  */