We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9bd8563 commit 2bb7078Copy full SHA for 2bb7078
mypyc/lib-rt/int_ops.c
@@ -654,6 +654,18 @@ void CPyInt32_Overflow() {
654
655
int16_t CPyLong_AsInt16(PyObject *o) {
656
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
669
PyLongObject *lobj = (PyLongObject *)o;
670
Py_ssize_t size = lobj->ob_base.ob_size;
671
if (likely(size == 1)) {
@@ -664,6 +676,7 @@ int16_t CPyLong_AsInt16(PyObject *o) {
676
} else if (likely(size == 0)) {
677
return 0;
678
}
679
+ #endif
680
681
// Slow path
682
int overflow;
0 commit comments