File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1515
1616_testinternalcapi = import_helper .import_module ("_testinternalcapi" )
1717
18- from _testinternalcapi import TIER2_THRESHOLD
18+ from _testinternalcapi import _PY_NSMALLPOSINTS , TIER2_THRESHOLD
1919
2020#For test of issue 136154
2121GLOBAL_136154 = 42
@@ -2093,6 +2093,10 @@ def testfunc(n):
20932093 self .assertNotIn ("_GUARD_TOS_INT" , uops )
20942094
20952095 def test_call_len_known_length_small_int (self ):
2096+ # Make sure that len(t) is optimized for a tuple of length 5.
2097+ # See https://github.com/python/cpython/issues/139393.
2098+ self .assertGreater (_PY_NSMALLPOSINTS , 5 )
2099+
20962100 def testfunc (n ):
20972101 x = 0
20982102 for _ in range (n ):
@@ -2113,13 +2117,17 @@ def testfunc(n):
21132117 self .assertNotIn ("_POP_TOP_LOAD_CONST_INLINE_BORROW" , uops )
21142118
21152119 def test_call_len_known_length (self ):
2120+ # Make sure that len(t) is not optimized for a tuple of length 2048.
2121+ # See https://github.com/python/cpython/issues/139393.
2122+ self .assertLess (_PY_NSMALLPOSINTS , 2048 )
2123+
21162124 def testfunc (n ):
21172125 class C :
2118- t = tuple (range (300 ))
2126+ t = tuple (range (2048 ))
21192127
21202128 x = 0
21212129 for _ in range (n ):
2122- if len (C .t ) == 300 : # comparison + guard removed
2130+ if len (C .t ) == 2048 : # comparison + guard removed
21232131 x += 1
21242132 return x
21252133
Original file line number Diff line number Diff line change 3434#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
3535#include "pycore_pylifecycle.h" // _PyInterpreterConfig_InitFromDict()
3636#include "pycore_pystate.h" // _PyThreadState_GET()
37+ #include "pycore_runtime_structs.h" // _PY_NSMALLPOSINTS
3738#include "pycore_unicodeobject.h" // _PyUnicode_TransformDecimalAndSpaceToASCII()
3839
3940#include "clinic/_testinternalcapi.c.h"
@@ -2576,6 +2577,10 @@ module_exec(PyObject *module)
25762577 return 1 ;
25772578 }
25782579
2580+ if (PyModule_AddIntMacro (module , _PY_NSMALLPOSINTS ) < 0 ) {
2581+ return 1 ;
2582+ }
2583+
25792584 return 0 ;
25802585}
25812586
You can’t perform that action at this time.
0 commit comments