mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-30416: Protect the optimizer during constant folding. (#4860)
It no longer spends much time doing complex calculations and no longer consumes much memory for creating large constants that will be dropped later. This fixes also bpo-21074.
This commit is contained in:
parent
a5552f023e
commit
2e3f570185
4 changed files with 144 additions and 27 deletions
|
|
@ -175,8 +175,15 @@ class TestTranforms(BytecodeTestCase):
|
|||
self.assertInBytecode(code, 'LOAD_CONST', 'b')
|
||||
|
||||
# Verify that large sequences do not result from folding
|
||||
code = compile('a="x"*1000', '', 'single')
|
||||
code = compile('a="x"*10000', '', 'single')
|
||||
self.assertInBytecode(code, 'LOAD_CONST', 10000)
|
||||
self.assertNotIn("x"*10000, code.co_consts)
|
||||
code = compile('a=1<<1000', '', 'single')
|
||||
self.assertInBytecode(code, 'LOAD_CONST', 1000)
|
||||
self.assertNotIn(1<<1000, code.co_consts)
|
||||
code = compile('a=2**1000', '', 'single')
|
||||
self.assertInBytecode(code, 'LOAD_CONST', 1000)
|
||||
self.assertNotIn(2**1000, code.co_consts)
|
||||
|
||||
def test_binary_subscr_on_unicode(self):
|
||||
# valid code get optimized
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue