Attaching a probably over-simplistic attempt at this patch, against the py3k branch.
This patch attempts to extend the replacement of
LOAD_CONST, ...., LOAD_CONST, BUILD_LIST, COMPARE_OP(in)
with
LOAD_CONST(tuple), COMPAREOP(in)
so that it also replaces:
LOAD_CONST, ...., LOAD_CONST, BUILD_SET, COMPARE_OP(in)
with
LOAD_CONST(tuple), COMPAREOP(in)
i.e. using a tuple, not a frozenset (on the grounds that the "in" conditions should at least still work); caveat: I'm relatively new to the innards of this code.
With this patch:
>>> dis.dis(lambda o: o in {1,2,3})
1 0 LOAD_FAST 0 (o)
3 LOAD_CONST 3 ((1, 2, 3))
6 COMPARE_OP 6 (in)
9 RETURN_VALUE
but:
>>> dis.dis(lambda o: o in {1,2,3,3,2,1})
1 0 LOAD_FAST 0 (o)
3 LOAD_CONST 3 ((1, 2, 3, 3, 2, 1))
6 COMPARE_OP 6 (in)
9 RETURN_VALUE
Is it worth me working on a rewrite to use a frozenset.
Hope this is helpful
Dave |