[IPython-user] Re: [IPython-dev] Patch for paren completion glitch

Fernando Perez Fernando.Perez at colorado.edu
Fri Jul 23 14:09:20 CDT 2004

Ville Vainio wrote:
> Fernando Perez wrote:

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

Ok.  A factor of 5 in speed is not worth the generality (esp. since we don't 
need the generality to begin with).

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

Just keep the string form, since it's a bit faster.  That escaping mess isn't 
really all that readable to begin with, so there's not much to worry here ;)

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

I can buy this.  All that escaping via regexes is a huge PITA, so if your 
tests show the shlex.split approach works, leave it.  Just remember to check 
with my hacked shlex_split, which is a LOT more primitive than the real thing 
in python 2.3.

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

Just put len(split) in an outside local, it's a trivial one-liner.  I can also 
do it with the final version.

If you send me this stuff this weekend, I'll make sure to put it in so 0.6.1 
has 'full' correct escaping of filenames.  Do you know if '[]' and '{}' need 
to be added to the list of characters to escape?  I'd never put those in a 
filename, but I guess it's not impossible.



More information about the IPython-user mailing list