git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] coccinelle: add rules to use strbuf_add() for adding buffers to strbufs
@ 2017-10-01 14:49 René Scharfe
  2017-10-01 14:54 ` [PATCH 2/2] commit: use strbuf_add() to add a buffer to a strbuf René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2017-10-01 14:49 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

strbuf_addf() can be used with "%.*s" to add a buffer of a specific size
to a strbuf, but the resulting code is longer, may require casting the
length to int and is less efficient than simply calling strbuf_add().
Add Coccinelle rules for transforming calls of the former type to the
latter.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 contrib/coccinelle/strbuf.cocci | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index 1d580e49b0..700a5f9c13 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -44,3 +44,15 @@ expression E1, E2;
 @@
 - strbuf_addstr(E1, real_path(E2));
 + strbuf_add_real_path(E1, E2);
+
+@@
+expression sb, buf, len;
+@@
+- strbuf_addf(sb, "%.*s", len, buf)
++ strbuf_add(sb, buf, len)
+
+@@
+expression sb, buf, len;
+@@
+- strbuf_addf(sb, "%.*s", (int)(len), buf)
++ strbuf_add(sb, buf, len)
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-02  5:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-01 14:49 [PATCH 1/2] coccinelle: add rules to use strbuf_add() for adding buffers to strbufs René Scharfe
2017-10-01 14:54 ` [PATCH 2/2] commit: use strbuf_add() to add a buffer to a strbuf René Scharfe
2017-10-02  5:18   ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).