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 think in the long run we'll want to provide a more generic way to 
> > transform paths to the way the current platform likes them, but in
> > the meantime I'm very much up for reducing copy and paste code;
> > I'll apply this tonight if no other Win32ers beat me to it. :-)
> 
> I don't disagree with that longer term plan.

I like it. typically this kind of stuff ends up in config.h with
auto-tools projects, but the file becomes a big heap. Something like 
platform_io.h might be a nice route. gather all of the IO related 
platform quirks into one spot, topically organized.

> On that subject, I remember 10 years ago so so, network drives on MS
> DOS named ux: and uy:
> Are 2 letter drive names still valid? Do they confuse most code?
> 
> Nicholas Clark

Attachment: signature.asc
Description: PGP signature

Reply via email to