]> git.ipfire.org Git - thirdparty/git.git/commitdiff
kwset: avoid using the comma operator unnecessarily
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 27 Mar 2025 11:52:56 +0000 (11:52 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 29 Mar 2025 00:38:09 +0000 (17:38 -0700)
The comma operator is a somewhat obscure C feature that is often used by
mistake and can even cause unintentional code flow. Better use a
semicolon instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
kwset.c

diff --git a/kwset.c b/kwset.c
index 1714eada608b86b14acf82ec4832c3c4d7e9205c..064329434e56d10f5135377b984c3cf6fe5cb5e7 100644 (file)
--- a/kwset.c
+++ b/kwset.c
@@ -197,10 +197,13 @@ kwsincr (kwset_t kws, char const *text, size_t len)
       while (link && label != link->label)
        {
          links[depth] = link;
-         if (label < link->label)
-           dirs[depth++] = L, link = link->llink;
-         else
-           dirs[depth++] = R, link = link->rlink;
+         if (label < link->label) {
+           dirs[depth++] = L;
+           link = link->llink;
+         } else {
+           dirs[depth++] = R;
+           link = link->rlink;
+         }
        }
 
       /* The current character doesn't have an outgoing link at
@@ -257,14 +260,14 @@ kwsincr (kwset_t kws, char const *text, size_t len)
                  switch (dirs[depth + 1])
                    {
                    case L:
-                     r = links[depth], t = r->llink, rl = t->rlink;
-                     t->rlink = r, r->llink = rl;
+                     r = links[depth]; t = r->llink; rl = t->rlink;
+                     t->rlink = r; r->llink = rl;
                      t->balance = r->balance = 0;
                      break;
                    case R:
-                     r = links[depth], l = r->llink, t = l->rlink;
-                     rl = t->rlink, lr = t->llink;
-                     t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
+                     r = links[depth]; l = r->llink; t = l->rlink;
+                     rl = t->rlink; lr = t->llink;
+                     t->llink = l; l->rlink = lr; t->rlink = r; r->llink = rl;
                      l->balance = t->balance != 1 ? 0 : -1;
                      r->balance = t->balance != (char) -1 ? 0 : 1;
                      t->balance = 0;
@@ -277,14 +280,14 @@ kwsincr (kwset_t kws, char const *text, size_t len)
                  switch (dirs[depth + 1])
                    {
                    case R:
-                     l = links[depth], t = l->rlink, lr = t->llink;
-                     t->llink = l, l->rlink = lr;
+                     l = links[depth]; t = l->rlink; lr = t->llink;
+                     t->llink = l; l->rlink = lr;
                      t->balance = l->balance = 0;
                      break;
                    case L:
-                     l = links[depth], r = l->rlink, t = r->llink;
-                     lr = t->llink, rl = t->rlink;
-                     t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
+                     l = links[depth]; r = l->rlink; t = r->llink;
+                     lr = t->llink; rl = t->rlink;
+                     t->llink = l; l->rlink = lr; t->rlink = r; r->llink = rl;
                      l->balance = t->balance != 1 ? 0 : -1;
                      r->balance = t->balance != (char) -1 ? 0 : 1;
                      t->balance = 0;
@@ -567,22 +570,22 @@ bmexec (kwset_t kws, char const *text, size_t size)
       {
        while (tp <= ep)
          {
-           d = d1[U(tp[-1])], tp += d;
-           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])]; tp += d;
+           d = d1[U(tp[-1])]; tp += d;
            if (d == 0)
              goto found;
-           d = d1[U(tp[-1])], tp += d;
-           d = d1[U(tp[-1])], tp += d;
-           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])]; tp += d;
+           d = d1[U(tp[-1])]; tp += d;
+           d = d1[U(tp[-1])]; tp += d;
            if (d == 0)
              goto found;
-           d = d1[U(tp[-1])], tp += d;
-           d = d1[U(tp[-1])], tp += d;
-           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])]; tp += d;
+           d = d1[U(tp[-1])]; tp += d;
+           d = d1[U(tp[-1])]; tp += d;
            if (d == 0)
              goto found;
-           d = d1[U(tp[-1])], tp += d;
-           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])]; tp += d;
+           d = d1[U(tp[-1])]; tp += d;
          }
        break;
       found:
@@ -649,7 +652,8 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
     mch = NULL;
   else
     {
-      mch = text, accept = kwset->trie;
+      mch = text;
+      accept = kwset->trie;
       goto match;
     }