File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -654,6 +654,18 @@ void CPyInt32_Overflow() {
654654
655655int16_t CPyLong_AsInt16 (PyObject * o ) {
656656 if (likely (PyLong_Check (o ))) {
657+ #if CPY_3_12_FEATURES
658+ PyLongObject * lobj = (PyLongObject * )o ;
659+ size_t tag = CPY_LONG_TAG (lobj );
660+ if (likely (tag == (1 << CPY_NON_SIZE_BITS ))) {
661+ // Fast path
662+ digit x = CPY_LONG_DIGIT (lobj , 0 );
663+ if (x < 0x8000 )
664+ return x ;
665+ } else if (likely (tag == CPY_SIGN_ZERO )) {
666+ return 0 ;
667+ }
668+ #else
657669 PyLongObject * lobj = (PyLongObject * )o ;
658670 Py_ssize_t size = lobj -> ob_base .ob_size ;
659671 if (likely (size == 1 )) {
@@ -664,6 +676,7 @@ int16_t CPyLong_AsInt16(PyObject *o) {
664676 } else if (likely (size == 0 )) {
665677 return 0 ;
666678 }
679+ #endif
667680 }
668681 // Slow path
669682 int overflow ;
You can’t perform that action at this time.
0 commit comments