@@ -2411,14 +2411,20 @@ def loop():
2411
2411
self .assertEqual (opt .get_count (), 1000 )
2412
2412
2413
2413
def test_long_loop (self ):
2414
- " Check that we aren't confused by EXTENDED_ARG"
2414
+ # Check that we aren't confused by EXTENDED_ARG
2415
2415
2416
2416
# Generate a new function at each call
2417
2417
ns = {}
2418
2418
exec (textwrap .dedent ("""
2419
2419
def nop():
2420
2420
pass
2421
2421
2422
+ def short_loop():
2423
+ for _ in range(10):
2424
+ nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2425
+ nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2426
+ nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2427
+
2422
2428
def long_loop():
2423
2429
for _ in range(10):
2424
2430
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
@@ -2429,14 +2435,21 @@ def long_loop():
2429
2435
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2430
2436
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2431
2437
""" ), ns , ns )
2438
+ short_loop = ns ['short_loop' ]
2432
2439
long_loop = ns ['long_loop' ]
2433
2440
2434
2441
opt = _testinternalcapi .get_counter_optimizer ()
2435
2442
with temporary_optimizer (opt ):
2436
2443
self .assertEqual (opt .get_count (), 0 )
2437
- long_loop ()
2444
+ short_loop ()
2438
2445
self .assertEqual (opt .get_count (), 10 )
2439
2446
2447
+ opt = _testinternalcapi .get_counter_optimizer ()
2448
+ with temporary_optimizer (opt ):
2449
+ self .assertEqual (opt .get_count (), 0 )
2450
+ long_loop () # Should not optimize!
2451
+ self .assertEqual (opt .get_count (), 0 )
2452
+
2440
2453
def test_code_restore_for_ENTER_EXECUTOR (self ):
2441
2454
def testfunc (x ):
2442
2455
i = 0
0 commit comments