Re: [Python-Dev] Prospective Peephole Transformation

2005-02-19 Thread M.-A. Lemburg
Raymond Hettinger wrote: Hmm, what if you'd teach tuples to do faster contains lookups for string or integer only content, e.g. by introducing sub-types for string-only and integer-only tuples ?! For a linear search, tuples are already pretty darned good and leave room for only microscopic O(n) im

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> I'm very glad you introduced the optimization of building small > constant tuples at compile-time. IMO, that was a pure win. It's been out in the wild for a while now with no issues. I'm somewhat happy with it. > the transformation isn't semantically correct on the > face of it. Well that

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Tim Peters
[Raymond Hettinger] > ... > The problem with the transformation was that it didn't handle the case > where x was non-hashable and it would raise a TypeError instead of > returning False as it should. I'm very glad you introduced the optimization of building small constant tuples at compile-time.

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> >>Wouldn't it help a lot more if the compiler would detect that > >>(1,2,3) is immutable and convert it into a constant at > >>compile time ?! > > > > > > Yes. We've already gotten it to that point: . . . > > Cool. Does that work for all tuples in the program ? It is limited to just tuples of

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread M.-A. Lemburg
Raymond Hettinger wrote: Wouldn't it help a lot more if the compiler would detect that (1,2,3) is immutable and convert it into a constant at compile time ?! Yes. We've already gotten it to that point: Python 2.5a0 (#46, Feb 15 2005, 19:11:35) [MSC v.1200 32 bit (Intel)] on win32 import dis dis.d

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> Wouldn't it help a lot more if the compiler would detect that > (1,2,3) is immutable and convert it into a constant at > compile time ?! Yes. We've already gotten it to that point: Python 2.5a0 (#46, Feb 15 2005, 19:11:35) [MSC v.1200 32 bit (Intel)] on win32 >>> import dis >>> dis.dis(compile

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread M.-A. Lemburg
Raymond Hettinger wrote: Based on some ideas from Skip, I had tried transforming the likes of "x in (1,2,3)" into "x in frozenset([1,2,3])". When applicable, it substantially simplified the generated code and converted the O(n) lookup into an O(1) step. There were substantial savings even if the