git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: git discussion list <git@vger.kernel.org>
Cc: Antoine Pelisse <apelisse@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 3/3] pretty: remove intermediate strbufs from pp_user_info()
Date: Thu, 25 Apr 2013 21:43:56 +0200	[thread overview]
Message-ID: <5179877C.8000300@lsrfire.ath.cx> (raw)
In-Reply-To: <51798705.7030108@lsrfire.ath.cx>

Use namebuf/namelen and mailbuf/maillen directly instead of copying
their contents into strbufs first.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 pretty.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/pretty.c b/pretty.c
index 6861997..9e43154 100644
--- a/pretty.c
+++ b/pretty.c
@@ -410,8 +410,6 @@ void pp_user_info(const struct pretty_print_context *pp,
 		  const char *what, struct strbuf *sb,
 		  const char *line, const char *encoding)
 {
-	struct strbuf name;
-	struct strbuf mail;
 	struct ident_split ident;
 	char *line_end;
 	const char *mailbuf, *namebuf;
@@ -433,42 +431,33 @@ void pp_user_info(const struct pretty_print_context *pp,
 	if (pp->mailmap)
 		map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
 
-	strbuf_init(&mail, 0);
-	strbuf_init(&name, 0);
-
-	strbuf_add(&mail, mailbuf, maillen);
-	strbuf_add(&name, namebuf, namelen);
-
 	if (pp->fmt == CMIT_FMT_EMAIL) {
 		strbuf_addstr(sb, "From: ");
-		if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) {
-			add_rfc2047(sb, name.buf, name.len,
+		if (needs_rfc2047_encoding(namebuf, namelen, RFC2047_ADDRESS)) {
+			add_rfc2047(sb, namebuf, namelen,
 				    encoding, RFC2047_ADDRESS);
 			max_length = 76; /* per rfc2047 */
-		} else if (needs_rfc822_quoting(name.buf, name.len)) {
+		} else if (needs_rfc822_quoting(namebuf, namelen)) {
 			struct strbuf quoted = STRBUF_INIT;
-			add_rfc822_quoted(&quoted, name.buf, name.len);
+			add_rfc822_quoted(&quoted, namebuf, namelen);
 			strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
 							-6, 1, max_length);
 			strbuf_release(&quoted);
 		} else {
-			strbuf_add_wrapped_bytes(sb, name.buf, name.len,
+			strbuf_add_wrapped_bytes(sb, namebuf, namelen,
 						 -6, 1, max_length);
 		}
 
 		if (max_length <
 		    last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
 			strbuf_addch(sb, '\n');
-		strbuf_addf(sb, " <%s>\n", mail.buf);
+		strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf);
 	} else {
-		strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
-			      (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
-			      "    ", name.buf, mail.buf);
+		strbuf_addf(sb, "%s: %.*s%.*s <%.*s>\n", what,
+			    (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, "    ",
+			    (int)namelen, namebuf, (int)maillen, mailbuf);
 	}
 
-	strbuf_release(&mail);
-	strbuf_release(&name);
-
 	switch (pp->fmt) {
 	case CMIT_FMT_MEDIUM:
 		strbuf_addf(sb, "Date:   %s\n",
-- 
1.8.2.1

      reply	other threads:[~2013-04-25 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25 19:40 [PATCH 1/3] pretty: simplify input line length calculation in pp_user_info() René Scharfe
2013-04-25 19:41 ` [PATCH 2/3] pretty: simplify output " René Scharfe
2013-04-25 19:43   ` René Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5179877C.8000300@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=apelisse@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).