36
36
void _PyFloat_ExactDealloc (PyObject * );
37
37
void _PyUnicode_ExactDealloc (PyObject * );
38
38
39
+ /// Return 0 for nonnegative, zero-or-one-digit ints, 1 otherwise
40
+ static inline int negative_or_multi_digit_int (const PyObject * sub ) {
41
+ assert (PyLong_CheckExact (sub ));
42
+ Py_ssize_t signed_magnitude = Py_SIZE (sub )
43
+ return ((size_t )signed_magnitude ) > 1 ;
44
+ }
45
+
39
46
/* Stack effect macros
40
47
* These will be mostly replaced by stack effect descriptions,
41
48
* but the tooling need to recognize them.
@@ -383,8 +390,7 @@ dummy_func(
383
390
DEOPT_IF (!PyList_CheckExact (list ), BINARY_SUBSCR );
384
391
385
392
// Deopt unless 0 <= sub < PyList_Size(list)
386
- Py_ssize_t signed_magnitude = Py_SIZE (sub );
387
- DEOPT_IF (invalid_index (signed_magnitude , 2 ), BINARY_SUBSCR );
393
+ DEOPT_IF (negative_or_multi_digit_int (sub ), BINARY_SUBSCR );
388
394
assert (((PyLongObject * )_PyLong_GetZero ())-> ob_digit [0 ] == 0 );
389
395
Py_ssize_t index = ((PyLongObject * )sub )-> ob_digit [0 ];
390
396
DEOPT_IF (index >= PyList_GET_SIZE (list ), BINARY_SUBSCR );
@@ -403,7 +409,7 @@ dummy_func(
403
409
404
410
// Deopt unless 0 <= sub < PyTuple_Size(list)
405
411
Py_ssize_t signed_magnitude = Py_SIZE (sub );
406
- DEOPT_IF (invalid_index ( signed_magnitude , 2 ), BINARY_SUBSCR );
412
+ DEOPT_IF (negative_or_multi_digit_int ( sub ), BINARY_SUBSCR );
407
413
assert (((PyLongObject * )_PyLong_GetZero ())-> ob_digit [0 ] == 0 );
408
414
Py_ssize_t index = ((PyLongObject * )sub )-> ob_digit [0 ];
409
415
DEOPT_IF (index >= PyTuple_GET_SIZE (tuple ), BINARY_SUBSCR );
@@ -507,7 +513,7 @@ dummy_func(
507
513
DEOPT_IF (!PyList_CheckExact (list ), STORE_SUBSCR );
508
514
509
515
// Ensure nonnegative, zero-or-one-digit ints.
510
- DEOPT_IF (invalid_index ( Py_SIZE ( sub ), 2 ), STORE_SUBSCR );
516
+ DEOPT_IF (negative_or_multi_digit_int ( sub ), STORE_SUBSCR );
511
517
Py_ssize_t index = ((PyLongObject * )sub )-> ob_digit [0 ];
512
518
// Ensure index < len(list)
513
519
DEOPT_IF (index >= PyList_GET_SIZE (list ), STORE_SUBSCR );
0 commit comments