On Sun, Mar 18, 2007 at 08:33:25PM -0700, Joshua Juran wrote:
> I can't imagine someone else hasn't already come up with
>
> cnv = path->strstart;
> while ( (cnv = strchr( cnv, '/' )) )
> {
> *cnv = '\\';
> }
>
> but I didn't see it posted, so here it is just in case.
Bikesheds, I know, but this will be faster:
cnv = path->strstart;
while ( (cnv = strchr( cnv, '/' )) )
{
*cnv++ = '\\';
}
because there's no way that the character at cnv can match '/' now :-)
Whether its faster than the loop without strchr probably depends on whether
the compiler inlines strchr(), whether the optimised version is efficient
on non-word aligned strings, and whether the optimised version doesn't have
a higher start cost. Either is better* than the current, and I don't have
a Win32 platform to test on, so can't test a change.
Nicholas Clark
* Yes, even in a non-speed critical area, because having poor algorithms around
will tempt people to base other code on them.