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

5 messages from 2007-07-22 to 2007-07-22. Participants: Marco Costalba, Junio C Hamano, Alex Riesen.
Thread: https://gitlist.dev/t/9134

## Marco Costalba, 2007-07-22 08:23

Subject: [PATCH] Avoid to duplicate commit message when is not encoded
Message-ID: <e5bfff550707220123g5826cbf5n3e2ff7256d9b5366@mail.gmail.com>
URL: https://gitlist.dev/e/e5bfff550707220123g5826cbf5n3e2ff7256d9b5366%40mail.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

```

## Junio C Hamano, 2007-07-22 08:40

Subject: Re: [PATCH] Avoid to duplicate commit message when is not encoded
Message-ID: <7vd4yksuer.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vd4yksuer.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <e5bfff550707220123g5826cbf5n3e2ff7256d9b5366@mail.gmail.com>

```
Thanks.

```

## Alex Riesen, 2007-07-22 08:52

Subject: Re: [PATCH] Avoid to duplicate commit message when is not encoded
Message-ID: <20070722085225.GB3408@steel.home>
URL: https://gitlist.dev/e/20070722085225.GB3408%40steel.home
In-Reply-To: <e5bfff550707220123g5826cbf5n3e2ff7256d9b5366@mail.gmail.com>

```
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

```

## Junio C Hamano, 2007-07-22 09:17

Subject: Re: [PATCH] Avoid to duplicate commit message when is not encoded
Message-ID: <7v4pjwssp0.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v4pjwssp0.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070722085225.GB3408@steel.home>

```
Alex Riesen <raa.lkml@gmail.com> writes:

> 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.

I've "fixed" them.

>> +		else
>> +			return NULL; // nothing to do
>
> And you better avoid such useless comments too

I think this one is probably a good-to-have.  It really needs a
bit of thinking why there is nothing to do in this case.  At
least for me it did ;-)

```

## Marco Costalba, 2007-07-22 22:04

Subject: Re: [PATCH] Avoid to duplicate commit message when is not encoded
Message-ID: <e5bfff550707221504g395580e6jdde1f37a810302f0@mail.gmail.com>
URL: https://gitlist.dev/e/e5bfff550707221504g395580e6jdde1f37a810302f0%40mail.gmail.com
In-Reply-To: <7v4pjwssp0.fsf@assigned-by-dhcp.cox.net>

```
On 7/22/07, Junio C Hamano <gitster@pobox.com> wrote:
> Alex Riesen <raa.lkml@gmail.com> writes:
>
> > 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.
>
> I've "fixed" them.
>

Sorry, I wrote them automatically without thinking it is better to
avoid them in C. BTW I would think it's more about coding style then
compiler support.

> >> +            else
> >> +                    return NULL; // nothing to do
> >
> > And you better avoid such useless comments too
>
> I think this one is probably a good-to-have.  It really needs a
> bit of thinking why there is nothing to do in this case.  At
> least for me it did ;-)
>

Me too ;-)

```
