https://github.com/python/cpython/commit/b5c8e6e1334f1756ead5e2cd5966731844428e2c
commit: b5c8e6e1334f1756ead5e2cd5966731844428e2c
branch: main
author: Chris Eibl <[email protected]>
committer: Eclips4 <[email protected]>
date: 2026-02-19T21:45:59+02:00
summary:
gh-100239: Use ``PyFloat_AS_DOUBLE`` and `_PyLong_IsZero`` in the float /
compactlong specializations (#144826)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-02-17-21-04-03.gh-issue-100239.LyVabQ.rst
M Python/specialize.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-02-17-21-04-03.gh-issue-100239.LyVabQ.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-17-21-04-03.gh-issue-100239.LyVabQ.rst
new file mode 100644
index 00000000000000..3cfc3e930d1e9d
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-17-21-04-03.gh-issue-100239.LyVabQ.rst
@@ -0,0 +1,2 @@
+Speedup ``BINARY_OP_EXTEND`` for exact floats and medium-size integers by up
+to 15%. Patch by Chris Eibl.
diff --git a/Python/specialize.c b/Python/specialize.c
index 4d3ba4acbbf038..1eabdb1b5b194e 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -2100,7 +2100,7 @@ float_compactlong_guard(PyObject *lhs, PyObject *rhs)
{
return (
PyFloat_CheckExact(lhs) &&
- !isnan(PyFloat_AsDouble(lhs)) &&
+ !isnan(PyFloat_AS_DOUBLE(lhs)) &&
PyLong_CheckExact(rhs) &&
_PyLong_IsCompact((PyLongObject *)rhs)
);
@@ -2110,7 +2110,7 @@ static inline int
nonzero_float_compactlong_guard(PyObject *lhs, PyObject *rhs)
{
return (
- float_compactlong_guard(lhs, rhs) && !PyLong_IsZero(rhs)
+ float_compactlong_guard(lhs, rhs) &&
!_PyLong_IsZero((PyLongObject*)rhs)
);
}
@@ -2118,7 +2118,7 @@ nonzero_float_compactlong_guard(PyObject *lhs, PyObject
*rhs)
static PyObject * \
(NAME)(PyObject *lhs, PyObject *rhs) \
{ \
- double lhs_val = PyFloat_AsDouble(lhs); \
+ double lhs_val = PyFloat_AS_DOUBLE(lhs); \
Py_ssize_t rhs_val = _PyLong_CompactValue((PyLongObject *)rhs); \
return PyFloat_FromDouble(lhs_val OP rhs_val); \
}
@@ -2137,7 +2137,7 @@ compactlong_float_guard(PyObject *lhs, PyObject *rhs)
PyLong_CheckExact(lhs) &&
_PyLong_IsCompact((PyLongObject *)lhs) &&
PyFloat_CheckExact(rhs) &&
- !isnan(PyFloat_AsDouble(rhs))
+ !isnan(PyFloat_AS_DOUBLE(rhs))
);
}
@@ -2145,7 +2145,7 @@ static inline int
nonzero_compactlong_float_guard(PyObject *lhs, PyObject *rhs)
{
return (
- compactlong_float_guard(lhs, rhs) && PyFloat_AsDouble(rhs) != 0.0
+ compactlong_float_guard(lhs, rhs) && PyFloat_AS_DOUBLE(rhs) != 0.0
);
}
@@ -2153,7 +2153,7 @@ nonzero_compactlong_float_guard(PyObject *lhs, PyObject
*rhs)
static PyObject * \
(NAME)(PyObject *lhs, PyObject *rhs) \
{ \
- double rhs_val = PyFloat_AsDouble(rhs); \
+ double rhs_val = PyFloat_AS_DOUBLE(rhs); \
Py_ssize_t lhs_val = _PyLong_CompactValue((PyLongObject *)lhs); \
return PyFloat_FromDouble(lhs_val OP rhs_val); \
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]