mirror of
https://github.com/git/git
synced 2024-10-30 04:01:21 +00:00
cocci: simplify "if (++u > 1)" to "if (u++)"
It is more common to use post-increment than pre-increment when the side effect is the primary thing we want in our code and in C in general (unlike C++). Initializing a variable to 0, incrementing it every time we do something, and checking if we have already done that thing to guard the code to do that thing, is easier to understand when written if (u++) ; /* we've done that! */ else do_it(); /* just once. */ but if you try to use pre-increment, you end up with a less natural looking if (++u > 1) Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cae598d998
commit
05b4ed61f4
1 changed files with 5 additions and 0 deletions
5
contrib/coccinelle/preincr.cocci
Normal file
5
contrib/coccinelle/preincr.cocci
Normal file
|
@ -0,0 +1,5 @@
|
|||
@ preincrement @
|
||||
identifier i;
|
||||
@@
|
||||
- ++i > 1
|
||||
+ i++
|
Loading…
Reference in a new issue