Re: g_strjoinv() is very slow



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]