@@ -1925,6 +1925,50 @@ def testfunc(n):
19251925 self .assertNotIn ("_GUARD_NOS_INT" , uops )
19261926 self .assertNotIn ("_GUARD_TOS_INT" , uops )
19271927
1928+ def test_get_len_with_const_tuple (self ):
1929+ def testfunc (n ):
1930+ x = 0.0
1931+ for _ in range (n ):
1932+ match (1 , 2 , 3 , 4 ):
1933+ case [_, _, _, _]:
1934+ x += 1.0
1935+ return x
1936+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
1937+ self .assertEqual (int (res ), TIER2_THRESHOLD )
1938+ uops = get_opnames (ex )
1939+ self .assertNotIn ("_GUARD_NOS_INT" , uops )
1940+ self .assertNotIn ("_GET_LEN" , uops )
1941+ self .assertIn ("_LOAD_CONST_INLINE_BORROW" , uops )
1942+
1943+ def test_get_len_with_non_const_tuple (self ):
1944+ def testfunc (n ):
1945+ x = 0.0
1946+ for _ in range (n ):
1947+ match object (), object ():
1948+ case [_, _]:
1949+ x += 1.0
1950+ return x
1951+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
1952+ self .assertEqual (int (res ), TIER2_THRESHOLD )
1953+ uops = get_opnames (ex )
1954+ self .assertNotIn ("_GUARD_NOS_INT" , uops )
1955+ self .assertNotIn ("_GET_LEN" , uops )
1956+ self .assertIn ("_LOAD_CONST_INLINE_BORROW" , uops )
1957+
1958+ def test_get_len_with_non_tuple (self ):
1959+ def testfunc (n ):
1960+ x = 0.0
1961+ for _ in range (n ):
1962+ match [1 , 2 , 3 , 4 ]:
1963+ case [_, _, _, _]:
1964+ x += 1.0
1965+ return x
1966+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
1967+ self .assertEqual (int (res ), TIER2_THRESHOLD )
1968+ uops = get_opnames (ex )
1969+ self .assertNotIn ("_GUARD_NOS_INT" , uops )
1970+ self .assertIn ("_GET_LEN" , uops )
1971+
19281972 def test_binary_op_subscr_tuple_int (self ):
19291973 def testfunc (n ):
19301974 x = 0
0 commit comments