Skip to content

Commit a0511b3

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97a17e7 commit a0511b3

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

pretty.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ void pp_user_info(const struct pretty_print_context *pp,
410410
const char *what, struct strbuf *sb,
411411
const char *line, const char *encoding)
412412
{
413-
struct strbuf name;
414-
struct strbuf mail;
415413
struct ident_split ident;
416414
char *line_end;
417415
const char *mailbuf, *namebuf;
@@ -433,42 +431,33 @@ void pp_user_info(const struct pretty_print_context *pp,
433431
if (pp->mailmap)
434432
map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
435433

436-
strbuf_init(&mail, 0);
437-
strbuf_init(&name, 0);
438-
439-
strbuf_add(&mail, mailbuf, maillen);
440-
strbuf_add(&name, namebuf, namelen);
441-
442434
if (pp->fmt == CMIT_FMT_EMAIL) {
443435
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,
446438
encoding, RFC2047_ADDRESS);
447439
max_length = 76; /* per rfc2047 */
448-
} else if (needs_rfc822_quoting(name.buf, name.len)) {
440+
} else if (needs_rfc822_quoting(namebuf, namelen)) {
449441
struct strbuf quoted = STRBUF_INIT;
450-
add_rfc822_quoted(&quoted, name.buf, name.len);
442+
add_rfc822_quoted(&quoted, namebuf, namelen);
451443
strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
452444
-6, 1, max_length);
453445
strbuf_release(&quoted);
454446
} else {
455-
strbuf_add_wrapped_bytes(sb, name.buf, name.len,
447+
strbuf_add_wrapped_bytes(sb, namebuf, namelen,
456448
-6, 1, max_length);
457449
}
458450

459451
if (max_length <
460452
last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
461453
strbuf_addch(sb, '\n');
462-
strbuf_addf(sb, " <%s>\n", mail.buf);
454+
strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf);
463455
} 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);
467459
}
468460

469-
strbuf_release(&mail);
470-
strbuf_release(&name);
471-
472461
switch (pp->fmt) {
473462
case CMIT_FMT_MEDIUM:
474463
strbuf_addf(sb, "Date: %s\n",

0 commit comments

Comments
 (0)