summaryrefslogtreecommitdiffstats
path: root/Objects
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 /Objects
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 'Objects')
-rw-r--r--Objects/bytearrayobject.c9
-rw-r--r--Objects/bytesobject.c2
2 files changed, 4 insertions, 7 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index ba2d347..cbe673a 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -6,6 +6,7 @@
#include "pycore_bytes_methods.h"
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_strhex.h" // _Py_strhex_with_sep()
+#include "pycore_long.h" // _PyLong_FromUnsignedChar()
#include "bytesobject.h"
/*[clinic input]
@@ -2428,7 +2429,6 @@ static PyObject *
bytearrayiter_next(bytesiterobject *it)
{
PyByteArrayObject *seq;
- PyObject *item;
assert(it != NULL);
seq = it->it_seq;
@@ -2437,11 +2437,8 @@ bytearrayiter_next(bytesiterobject *it)
assert(PyByteArray_Check(seq));
if (it->it_index < PyByteArray_GET_SIZE(seq)) {
- item = PyLong_FromLong(
- (unsigned char)PyByteArray_AS_STRING(seq)[it->it_index]);
- if (item != NULL)
- ++it->it_index;
- return item;
+ return _PyLong_FromUnsignedChar(
+ (unsigned char)PyByteArray_AS_STRING(seq)[it->it_index++]);
}
it->it_seq = NULL;
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index fd1c58c..0039532 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3133,7 +3133,7 @@ striter_next(striterobject *it)
assert(PyBytes_Check(seq));
if (it->it_index < PyBytes_GET_SIZE(seq)) {
- return PyLong_FromLong(
+ return _PyLong_FromUnsignedChar(
(unsigned char)seq->ob_sval[it->it_index++]);
}