]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-100239: Use ``PyFloat_AS_DOUBLE`` and `_PyLong_IsZero`` in the float / compactlong...
authorChris Eibl <138194463+chris-eibl@users.noreply.github.com>
Thu, 19 Feb 2026 19:45:59 +0000 (20:45 +0100)
committerGitHub <noreply@github.com>
Thu, 19 Feb 2026 19:45:59 +0000 (21:45 +0200)
Misc/NEWS.d/next/Core_and_Builtins/2026-02-17-21-04-03.gh-issue-100239.LyVabQ.rst [new file with mode: 0644]
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 (file)
index 0000000..3cfc3e9
--- /dev/null
@@ -0,0 +1,2 @@
+Speedup ``BINARY_OP_EXTEND`` for exact floats and medium-size integers by up
+to 15%. Patch by Chris Eibl.
index 4d3ba4acbbf038443af1650104b1f0ad745db0b9..1eabdb1b5b194e8008b78200ebc3eafcf9e1dfe2 100644 (file)
@@ -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); \
     }