On Mar 18, 2007, at 3:59 PM, Mike Mattie wrote:
On Sun, 18 Mar 2007 19:30:35 +0000
Nicholas Clark <[EMAIL PROTECTED]> wrote:
On Sun, Mar 18, 2007 at 03:35:14PM +0000, Jonathan Worthington wrote:
Mike Mattie (via RT) wrote:
While mucking around in src/library.c I noticed some cut & paste
duplication. It looked like a fairly simple hoist so I have
attached the changes I made.
[snip]
while ( (cnv = strchr(path->strstart, '/')) )
*cnv = '\\';
[snip]
But painfully inefficiently. (Probably this doesn't matter here)
I suspect the loop wants to become
cnv = path->strstart;
while (*cnv) {
if (*cnv == '/')
*cnv = '\\';
}
++cnv;
}
which should at least be O(n) rather than O(n²) for a string of
length n.
you are correct. I do like the strchr() call over a manual iteration
though. GCC will aggressively optimize some of the standard library
string functions, and I would guess that many other compilers do as
well.
It at least leaves the door open to picking up the benefits of
future hardware/compiler changes. It's also more friendly to static-
analysis.
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.
Josh