[PATCH] Avoid to duplicate commit message when is not encoded

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] Avoid to duplicate commit message when is not encoded

From: Marco Costalba <hidden>
Date: 2016-06-15 22:43:23

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 <redacted>
---
 commit.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/commit.c b/commit.c
index 4c5dfa9..ba8413b 100644
--- a/commit.c
+++ b/commit.c
@@ -721,7 +721,10 @@ static char *logmsg_reencode(const
 	encoding = get_header(commit, "encoding");
 	use_encoding = encoding ? encoding : utf8;
  	if (!strcmp(use_encoding, output_encoding))
-		out = xstrdup(commit->buffer);
+		if (encoding) // we'll strip encoding header later
+			out = xstrdup(commit->buffer);
+		else
+			return NULL; // nothing to do
 	else
 		out = reencode_string(commit->buffer,
 				      output_encoding, use_encoding);
-- 
1.5.3.rc2.23.g4c77-dirty

Re: [PATCH] Avoid to duplicate commit message when is not encoded

From: Alex Riesen <hidden>
Date: 2016-06-15 22:43:23

Marco Costalba, Sun, Jul 22, 2007 10:23:05 +0200:
+		if (encoding) // we'll strip encoding header later
You better avoid using C++ comments, not all C compilers support them.
+		else
+			return NULL; // nothing to do
And you better avoid such useless comments too
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help