summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-03-23 08:30:05 (GMT)
committerGitHub <noreply@github.com>2022-03-23 08:30:05 (GMT)
commitbd1cf6ecee76bcdce87b4f69567b95756ecf5a4c (patch)
tree250124df65639f63a413564c3254b26b881d4371 /Include
parent894d0ea5afa822c23286e9e68ed80bb1122b402d (diff)
downloadcpython-bd1cf6ecee76bcdce87b4f69567b95756ecf5a4c.zip
cpython-bd1cf6ecee76bcdce87b4f69567b95756ecf5a4c.tar.gz
cpython-bd1cf6ecee76bcdce87b4f69567b95756ecf5a4c.tar.bz2
bpo-47012: speed up iteration of bytes and bytearray (GH-31867)
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_long.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h
index 436bf08..a337624 100644
--- a/Include/internal/pycore_long.h
+++ b/Include/internal/pycore_long.h
@@ -23,8 +23,9 @@ extern void _PyLong_FiniTypes(PyInterpreterState *interp);
#define _PyLong_SMALL_INTS _Py_SINGLETON(small_ints)
// _PyLong_GetZero() and _PyLong_GetOne() must always be available
-#if _PY_NSMALLPOSINTS < 2
-# error "_PY_NSMALLPOSINTS must be greater than 1"
+// _PyLong_FromUnsignedChar must always be available
+#if _PY_NSMALLPOSINTS < 257
+# error "_PY_NSMALLPOSINTS must be greater than or equal to 257"
#endif
// Return a borrowed reference to the zero singleton.
@@ -37,6 +38,11 @@ static inline PyObject* _PyLong_GetZero(void)
static inline PyObject* _PyLong_GetOne(void)
{ return (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+1]; }
+static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
+{
+ return Py_NewRef((PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+i]);
+}
+
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);