mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
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:
parent
dbecd93b72
commit
a164574937
2 changed files with 58 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue