Skip to content

Commit 22542b6

Browse files
dschogitster
authored andcommitted
kwset: avoid using the comma operator unnecessarily
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 <[email protected]> Acked-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 38c696d commit 22542b6

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

kwset.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,13 @@ kwsincr (kwset_t kws, char const *text, size_t len)
197197
while (link && label != link->label)
198198
{
199199
links[depth] = link;
200-
if (label < link->label)
201-
dirs[depth++] = L, link = link->llink;
202-
else
203-
dirs[depth++] = R, link = link->rlink;
200+
if (label < link->label) {
201+
dirs[depth++] = L;
202+
link = link->llink;
203+
} else {
204+
dirs[depth++] = R;
205+
link = link->rlink;
206+
}
204207
}
205208

206209
/* The current character doesn't have an outgoing link at
@@ -257,14 +260,14 @@ kwsincr (kwset_t kws, char const *text, size_t len)
257260
switch (dirs[depth + 1])
258261
{
259262
case L:
260-
r = links[depth], t = r->llink, rl = t->rlink;
261-
t->rlink = r, r->llink = rl;
263+
r = links[depth]; t = r->llink; rl = t->rlink;
264+
t->rlink = r; r->llink = rl;
262265
t->balance = r->balance = 0;
263266
break;
264267
case R:
265-
r = links[depth], l = r->llink, t = l->rlink;
266-
rl = t->rlink, lr = t->llink;
267-
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
268+
r = links[depth]; l = r->llink; t = l->rlink;
269+
rl = t->rlink; lr = t->llink;
270+
t->llink = l; l->rlink = lr; t->rlink = r; r->llink = rl;
268271
l->balance = t->balance != 1 ? 0 : -1;
269272
r->balance = t->balance != (char) -1 ? 0 : 1;
270273
t->balance = 0;
@@ -277,14 +280,14 @@ kwsincr (kwset_t kws, char const *text, size_t len)
277280
switch (dirs[depth + 1])
278281
{
279282
case R:
280-
l = links[depth], t = l->rlink, lr = t->llink;
281-
t->llink = l, l->rlink = lr;
283+
l = links[depth]; t = l->rlink; lr = t->llink;
284+
t->llink = l; l->rlink = lr;
282285
t->balance = l->balance = 0;
283286
break;
284287
case L:
285-
l = links[depth], r = l->rlink, t = r->llink;
286-
lr = t->llink, rl = t->rlink;
287-
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
288+
l = links[depth]; r = l->rlink; t = r->llink;
289+
lr = t->llink; rl = t->rlink;
290+
t->llink = l; l->rlink = lr; t->rlink = r; r->llink = rl;
288291
l->balance = t->balance != 1 ? 0 : -1;
289292
r->balance = t->balance != (char) -1 ? 0 : 1;
290293
t->balance = 0;
@@ -567,22 +570,22 @@ bmexec (kwset_t kws, char const *text, size_t size)
567570
{
568571
while (tp <= ep)
569572
{
570-
d = d1[U(tp[-1])], tp += d;
571-
d = d1[U(tp[-1])], tp += d;
573+
d = d1[U(tp[-1])]; tp += d;
574+
d = d1[U(tp[-1])]; tp += d;
572575
if (d == 0)
573576
goto found;
574-
d = d1[U(tp[-1])], tp += d;
575-
d = d1[U(tp[-1])], tp += d;
576-
d = d1[U(tp[-1])], tp += d;
577+
d = d1[U(tp[-1])]; tp += d;
578+
d = d1[U(tp[-1])]; tp += d;
579+
d = d1[U(tp[-1])]; tp += d;
577580
if (d == 0)
578581
goto found;
579-
d = d1[U(tp[-1])], tp += d;
580-
d = d1[U(tp[-1])], tp += d;
581-
d = d1[U(tp[-1])], tp += d;
582+
d = d1[U(tp[-1])]; tp += d;
583+
d = d1[U(tp[-1])]; tp += d;
584+
d = d1[U(tp[-1])]; tp += d;
582585
if (d == 0)
583586
goto found;
584-
d = d1[U(tp[-1])], tp += d;
585-
d = d1[U(tp[-1])], tp += d;
587+
d = d1[U(tp[-1])]; tp += d;
588+
d = d1[U(tp[-1])]; tp += d;
586589
}
587590
break;
588591
found:
@@ -649,7 +652,8 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
649652
mch = NULL;
650653
else
651654
{
652-
mch = text, accept = kwset->trie;
655+
mch = text;
656+
accept = kwset->trie;
653657
goto match;
654658
}
655659

0 commit comments

Comments
 (0)