Transform "x in (1,2,3)" to "x in frozenset([1,2,3])".

Inspired by Skip's idea to recognize the throw-away nature of sequences
in this context and to transform their type to one with better performance.
This commit is contained in:
Raymond Hettinger 2005-02-06 22:05:42 +00:00
parent dbecd93b72
commit a164574937
2 changed files with 58 additions and 1 deletions

View file

@ -133,6 +133,16 @@ class TestTranforms(unittest.TestCase):
asm = dis_single('a="x"*1000')
self.assert_('(1000)' in asm)
def test_set_conversion(self):
for line in (
'x in (1,2,3)',
'x not in (1,2,3)',
'not x in (1,2,3)',
'not x not in (1,2,3)',
):
asm = dis_single(line)
self.assert_('frozenset' in asm)
def test_elim_extra_return(self):
# RETURN LOAD_CONST None RETURN --> RETURN
def f(x):