[Python-Dev] Slices and "==" optimization

M.-A. Lemburg mal@lemburg.com
Tue, 30 Oct 2001 09:25:28 +0100


While writing yet another XML parser I have come across two
things which would seem nice to have:

1. Even though you can construct slice objects in Python
   using slice(left,right), you can't really do anything
   with them; at least not on the standard types (Numeric's
   arrays work with them just fine).

   Couldn't we add some functionality which makes them
   compatible to lists and tuples (and perhaps even in a
   generic way for other sequences using PySequence_GetItem())
   too ?

   I thinking of extending the __getitem__ hook to accept
   slice objects. You could then maintain slices to an
   object in say a list and apply them to the underlying text
   as needed, e.g.

   s = slice(1,4)
   l = range(10)
   l[s] == [1, 2, 3]

2. Looking through the code for '==' the optimization for
   'a == a' seems too far down the call stack. Since interning
   strings makes this case rather common, I'd suggest to
   lift the optimization into the ceval loop (right along side
   with the INT op INT optimization).

Thoughts ?

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/