Skip to content

Commit c4640fe

Browse files
mcostalbagitster
authored andcommitted
Avoid to duplicate commit message when is not encoded
When a commit message doesn't have encoding information and encoding output is utf-8 (default) then an useless xstrdup() of commit message is done. If we assume most of users live in an utf-8 world, this useless copy is the common case. Performance issue found with KCachegrind. Signed-off-by: Marco Costalba <mcostalba@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e5633cb commit c4640fe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

commit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,10 @@ static char *logmsg_reencode(const struct commit *commit,
721721
encoding = get_header(commit, "encoding");
722722
use_encoding = encoding ? encoding : utf8;
723723
if (!strcmp(use_encoding, output_encoding))
724-
out = xstrdup(commit->buffer);
724+
if (encoding) /* we'll strip encoding header later */
725+
out = xstrdup(commit->buffer);
726+
else
727+
return NULL; /* nothing to do */
725728
else
726729
out = reencode_string(commit->buffer,
727730
output_encoding, use_encoding);

0 commit comments

Comments
 (0)