git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MCMarco Costalba <mcostalba@gmail.com>
Date
Jul 22, 2007, 08:23 UTC
Message-ID
<e5bfff550707220123g5826cbf5n3e2ff7256d9b5366@mail.gmail.com>

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>
---
 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
Next: Junio C Hamano
Message 1 of 5 in “Avoid to duplicate commit message when is not encoded”
  1. Avoid to duplicate commit message when is not encodedMarco Costalba, Jul 22, 2007
  2. Junio C HamanoJul 22, 2007
  3. Alex RiesenJul 22, 2007
  4. Junio C HamanoJul 22, 2007
  5. Marco CostalbaJul 22, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.