pretty: remove intermediate strbufs from pp_user_info()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Apr 25, 2013 at 21:43 UTC a0511b3934287d0dbffdb28ff6f00a220f794e06
1 file changed +9 -20
pretty.c
+9 -20
@@ -410,8 +410,6 @@ void pp_user_info(const struct pretty_print_context *pp,
410 const char *what, struct strbuf *sb,
411 const char *line, const char *encoding)
412 {
413 - struct strbuf name;
414 - struct strbuf mail;
413 struct ident_split ident;
414 char *line_end;
415 const char *mailbuf, *namebuf;
@@ -433,42 +431,33 @@ void pp_user_info(const struct pretty_print_context *pp,
431 if (pp->mailmap)
432 map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
433
436 - strbuf_init(&mail, 0);
437 - strbuf_init(&name, 0);
438 -
439 - strbuf_add(&mail, mailbuf, maillen);
440 - strbuf_add(&name, namebuf, namelen);
441 -
434 if (pp->fmt == CMIT_FMT_EMAIL) {
435 strbuf_addstr(sb, "From: ");
444 - if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) {
445 - add_rfc2047(sb, name.buf, name.len,
436 + if (needs_rfc2047_encoding(namebuf, namelen, RFC2047_ADDRESS)) {
437 + add_rfc2047(sb, namebuf, namelen,
438 encoding, RFC2047_ADDRESS);
439 max_length = 76; /* per rfc2047 */
448 - } else if (needs_rfc822_quoting(name.buf, name.len)) {
440 + } else if (needs_rfc822_quoting(namebuf, namelen)) {
441 struct strbuf quoted = STRBUF_INIT;
450 - add_rfc822_quoted(&quoted, name.buf, name.len);
442 + add_rfc822_quoted(&quoted, namebuf, namelen);
443 strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
444 -6, 1, max_length);
445 strbuf_release(&quoted);
446 } else {
455 - strbuf_add_wrapped_bytes(sb, name.buf, name.len,
447 + strbuf_add_wrapped_bytes(sb, namebuf, namelen,
448 -6, 1, max_length);
449 }
450
451 if (max_length <
452 last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
453 strbuf_addch(sb, '\n');
462 - strbuf_addf(sb, " <%s>\n", mail.buf);
454 + strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf);
455 } else {
464 - strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
465 - (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
466 - " ", name.buf, mail.buf);
456 + strbuf_addf(sb, "%s: %.*s%.*s <%.*s>\n", what,
457 + (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, " ",
458 + (int)namelen, namebuf, (int)maillen, mailbuf);
459 }
460
469 - strbuf_release(&mail);
470 - strbuf_release(&name);
471 -
461 switch (pp->fmt) {
462 case CMIT_FMT_MEDIUM:
463 strbuf_addf(sb, "Date: %s\n",