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.
> >
> >I do not have a win32 platform available for testing so I haven't been 
> >able to compile test it.
> >
> >    while ( (cnv = strchr(path->strstart, '/')) )
> >     *cnv = '\\';
> >
> >this looks totally broken. unless path->strstart is a stateful iterator 
> >this will only convert the first instance of a '/' character.
> >  
> Nope, it works fine. The first time you call strchr it finds the first 
> /, but by the second time you run it that has been transformed to a \ so 
> it finds the "second" / (now the first one), and so forth.

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.

> 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.

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

Reply via email to