Skip to content

Commit 02df679

Browse files
Use _PyLong_IsNegative instead of _PyLong_Sign if appropriate. (GH-120493)
It is faster and more obvious.
1 parent 35e998f commit 02df679

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ PyCArrayType_init(PyObject *self, PyObject *args, PyObject *kwds)
16061606
goto error;
16071607
}
16081608

1609-
if (_PyLong_Sign(length_attr) == -1) {
1609+
if (_PyLong_IsNegative((PyLongObject *)length_attr)) {
16101610
Py_DECREF(length_attr);
16111611
PyErr_SetString(PyExc_ValueError,
16121612
"The '_length_' attribute must not be negative");

Modules/_interpretersmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "pycore_crossinterp.h" // struct _xid
1111
#include "pycore_interp.h" // _PyInterpreterState_IDIncref()
1212
#include "pycore_initconfig.h" // _PyErr_SetFromPyStatus()
13-
#include "pycore_long.h" // _PyLong_IsNegative()
1413
#include "pycore_modsupport.h" // _PyArg_BadArgument()
1514
#include "pycore_namespace.h" // _PyNamespace_New()
1615
#include "pycore_pybuffer.h" // _PyBuffer_ReleaseInInterpreterAndRawFree()

Modules/_io/_iomodule.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "Python.h"
1111
#include "pycore_abstract.h" // _PyNumber_Index()
1212
#include "pycore_initconfig.h" // _PyStatus_OK()
13-
#include "pycore_long.h" // _PyLong_Sign()
13+
#include "pycore_long.h" // _PyLong_IsNegative()
1414
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
1515
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1616

@@ -544,10 +544,7 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err)
544544
*/
545545
if (!err) {
546546
assert(PyLong_Check(value));
547-
/* Whether or not it is less than or equal to
548-
zero is determined by the sign of ob_size
549-
*/
550-
if (_PyLong_Sign(value) < 0)
547+
if (_PyLong_IsNegative((PyLongObject *)value))
551548
result = PY_OFF_T_MIN;
552549
else
553550
result = PY_OFF_T_MAX;

0 commit comments

Comments
 (0)