Re: g_strjoinv() is very slow
- From: Raja R Harinath <harinath cs umn edu>
- To: Sean Middleditch <sean middleditch iname com>
- Cc: David Odin <David Odin bigfoot com>, Havoc Pennington <hp redhat com>, gtk-devel-list gnome org
- Subject: Re: g_strjoinv() is very slow
- Date: 24 Sep 2000 16:01:08 -0500
Sean Middleditch <sean middleditch iname com> writes:
> David Odin wrote:
> > OK. Thanks for all your comments.
> > I've attached a new version which takes all your remarks in account.
>
> OK, just to point something out, all those for (int i = 1; array[i] != NULL;
> i++) and whatnot's in the for loops should be something like
>
> for (char *c = str + 1; *c != 0; c ++)
'array' is an array of strings, not a string. So your code isn't
exactly suitable. The loop is also used to count the number of
elements -- so it is more natural to use indices rather than pointers.
> That way, you don't have to do an index lookup on every
> iteration... it'll speed the code up a lot (one less multiplication
> per iteration).
The compiler is more than happy to handle this for us ;-)
> I don't know if any of this makes any difference, but seeing how the
> thread subject is complaining about speed issues, I thought I might
> mention this. Being a game programmer, I'm rather used to doing
> everything possible for even the slightest speed increase... ~,^
The discussion is about replacing an O(n*n) algorithm with an O(n)
algorithm. What you propose is a micro-optimization which GCC is
usually capable of handling itself.
- Hari
--
Raja R Harinath ------------------------------ harinath cs umn edu
"When all else fails, read the instructions." -- Cahn's Axiom
"Our policy is, when in doubt, do the right thing." -- Roy L Ash
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]