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>
Marco Costalba committed
Jul 22, 2007 at 10:23 UTC
c4640fe8d9e25fd3e206a39233c71a6dbb68917e
1 file changed
+4
-1
commit.c
+4
-1
@@ -721,7 +721,10 @@ static char *logmsg_reencode(const struct commit *commit,
721
encoding = get_header(commit, "encoding");
722
use_encoding = encoding ? encoding : utf8;
723
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 */
728
else
729
out = reencode_string(commit->buffer,
730
output_encoding, use_encoding);