[IPython-user] Re: [IPython-dev] Patch for paren completion glitch
Ville Vainio
vivainio at kolumbus.fi
Fri Jul 23 01:54:45 CDT 2004
Fernando Perez wrote:
> match, which can be a lot in a big directory. People expect
> tab-completion to be near-instantaneous, and I'd like to keep it that
> way. In particular, I think that
>
...
>
> is essentially:
>
> # Alternative unprotect_filename
> # About 5 times faster than the original
> unprotect_filename2 = lambda s:s.replace('\\','')
>
> Am I right? If that's the case, it can (and should) be explicitly
> inlined, since function call overhead in
Pretty much - I made it unnecessarily generic by implementing escaping
of backslashes, which is not needed in filenames anyway.
> tests. I also checked the protect_filename, and could manage very
> minor improvements by using a string instead of a list for the 'in'
> check: checking 'char in string' is faster than 'char in list_of_chars'.
It was a string at first for me too, but I made it a list in the name of
readability. I guess it doesn't matter either way.
> It would be worth also checking if this:
>
> + lsplit = shlex.split(lbuf[:self.readline.get_endidx()])[-1]
>
> is faster when done with a regexp instead of shlex.split (the latter
> is HUGE, so I expect it to be pretty slow).
I'm not sure it matters - it's only called once, and shlex.slit handled
all the quote-unquote-escape stuff for free.
>
> Here:
> + matches = [text0 + protect_filename(f[len(lsplit):])
> for f in m0]
>
> the len(lsplit) should be kept in a local outside, since python does
> not lift constants out of loops or listcomps (the python compiler is
> absolutely primitive in the optimizations it attempts).
>
> I agree that it's necessary to do this correctly because people do
> have filenames with these chars in them. But since this is smack in
> the middle of the interactive loop, I really want to be sure that the
> code is as absolutely tight as possible. Also keep in mind that there
> may be users out there with hardware
But these are matches that have already been deemed appropriate, and
it's expected that the "comfort zone" has already been missed if there
are several screenfulls of stuff. I'm pretty sure nobody would ever
notice the time difference, but since the optimization is trivial it's
possibly worth doing anyway...
More information about the IPython-user
mailing list