git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MEMarkus Elfring <markus.elfring@web.de>
Date
Nov 12, 2019, 16:55 UTC
Message-ID
<31d2b9c8-31ec-4921-d38d-12712de819a7@web.de>
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(-)
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
Message 1 of 1 in “coccinelle: merge eight rules from strbuf.cocci”
  1. coccinelle: merge eight rules from strbuf.cocciMarkus Elfring, Nov 12, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.