threads / patch / 52244

patchcoccinelle: merge eight rules from strbuf.cocci

Subject: [PATCH] coccinelle: merge eight rules from strbuf.cocci

## tl;dr

One message between Nov 12, 2019 and Nov 12, 2019. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Markus Elfring· Nov 12, 2019, 16:55 UTC · lore
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 12 Nov 2019 17:50:13 +0100

This script contained transformation rules for the semantic patch language which used similar code. Combine these rules by using two SmPL disjunctions so that the run time characteristics can be nicer because of common usage of a few metavariables.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 contrib/coccinelle/strbuf.cocci | 49 +++++++++++----------------------
 1 file changed, 16 insertions(+), 33 deletions(-)
Show changes to contrib/coccinelle/strbuf.cocci +16 −34
diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index d9ada69b43..b66c9bf8e3 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -1,7 +1,11 @@
-@ strbuf_addf_with_format_only @
+@replacement1@
 expression E;
 constant fmt !~ "%";
+struct strbuf SB;
+struct strbuf *SBP;
+format F =~ "s";
 @@
+(
 - strbuf_addf
 + strbuf_addstr
   (E,
@@ -11,52 +15,31 @@ constant fmt !~ "%";
   _(fmt)
 )
   );
-
-@@
-expression E;
-struct strbuf SB;
-format F =~ "s";
-@@
+|
 - strbuf_addf(E, "%@F@", SB.buf);
 + strbuf_addbuf(E, &SB);
-
-@@
-expression E;
-struct strbuf *SBP;
-format F =~ "s";
-@@
+|
 - strbuf_addf(E, "%@F@", SBP->buf);
 + strbuf_addbuf(E, SBP);
-
-@@
-expression E;
-struct strbuf SB;
-@@
+|
 - strbuf_addstr(E, SB.buf);
 + strbuf_addbuf(E, &SB);
-
-@@
-expression E;
-struct strbuf *SBP;
-@@
+|
 - strbuf_addstr(E, SBP->buf);
 + strbuf_addbuf(E, SBP);
+)

-@@
-expression E1, E2;
+@replacement2@
+expression E1, E2, E3;
 format F =~ "s";
 @@
+(
 - strbuf_addf(E1, "%@F@", E2);
 + strbuf_addstr(E1, E2);
-
-@@
-expression E1, E2, E3;
-@@
+|
 - strbuf_addstr(E1, find_unique_abbrev(E2, E3));
 + strbuf_add_unique_abbrev(E1, E2, E3);
-
-@@
-expression E1, E2;
-@@
+|
 - strbuf_addstr(E1, real_path(E2));
 + strbuf_add_real_path(E1, E2);
+)
--
2.24.0

← back to recent threads