git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Avoid to duplicate commit message when is not encoded
@ 2007-07-22  8:23 Marco Costalba
  2007-07-22  8:40 ` Junio C Hamano
  2007-07-22  8:52 ` Alex Riesen
  0 siblings, 2 replies; 5+ messages in thread
From: Marco Costalba @ 2007-07-22  8:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid to duplicate commit message when is not encoded
  2007-07-22  8:23 [PATCH] Avoid to duplicate commit message when is not encoded Marco Costalba
@ 2007-07-22  8:40 ` Junio C Hamano
  2007-07-22  8:52 ` Alex Riesen
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2007-07-22  8:40 UTC (permalink / raw)
  To: Marco Costalba; +Cc: Git Mailing List

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid to duplicate commit message when is not encoded
  2007-07-22  8:23 [PATCH] Avoid to duplicate commit message when is not encoded Marco Costalba
  2007-07-22  8:40 ` Junio C Hamano
@ 2007-07-22  8:52 ` Alex Riesen
  2007-07-22  9:17   ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Alex Riesen @ 2007-07-22  8:52 UTC (permalink / raw)
  To: Marco Costalba; +Cc: Junio C Hamano, Git Mailing List

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid to duplicate commit message when is not encoded
  2007-07-22  8:52 ` Alex Riesen
@ 2007-07-22  9:17   ` Junio C Hamano
  2007-07-22 22:04     ` Marco Costalba
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2007-07-22  9:17 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Marco Costalba, Git Mailing List

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 ;-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid to duplicate commit message when is not encoded
  2007-07-22  9:17   ` Junio C Hamano
@ 2007-07-22 22:04     ` Marco Costalba
  0 siblings, 0 replies; 5+ messages in thread
From: Marco Costalba @ 2007-07-22 22:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Alex Riesen, Git Mailing List

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 ;-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-07-22 22:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-22  8:23 [PATCH] Avoid to duplicate commit message when is not encoded Marco Costalba
2007-07-22  8:40 ` Junio C Hamano
2007-07-22  8:52 ` Alex Riesen
2007-07-22  9:17   ` Junio C Hamano
2007-07-22 22:04     ` Marco Costalba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).