summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-11-22 20:00:53 (GMT)
committerGitHub <noreply@github.com>2020-11-22 20:00:53 (GMT)
commit313467efdc23a1ec8662b77d2001642be598f80a (patch)
tree1a50301bd304e7dd0113060a4b86a228ddebf943 /Objects/bytearrayobject.c
parent5ef53a88f3130cfcf9a9be3abd2ff2f997902647 (diff)
downloadcpython-313467efdc23a1ec8662b77d2001642be598f80a.zip
cpython-313467efdc23a1ec8662b77d2001642be598f80a.tar.gz
cpython-313467efdc23a1ec8662b77d2001642be598f80a.tar.bz2
bpo-42435: Speed up comparison of bytes and bytearray object (GH--23461)
* Speed up comparison of bytes objects with non-bytes objects when option -b is specified. * Speed up comparison of bytarray objects with non-buffer object.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 8b57fb6..805707a 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1005,23 +1005,19 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
{
Py_ssize_t self_size, other_size;
Py_buffer self_bytes, other_bytes;
- int cmp, rc;
+ int cmp;
/* Bytes can be compared to anything that supports the (binary)
buffer API. Except that a comparison with Unicode is always an
error, even if the comparison is for equality. */
- rc = PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type);
- if (!rc)
- rc = PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type);
- if (rc < 0)
- return NULL;
- if (rc) {
- if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) {
- if (PyErr_WarnEx(PyExc_BytesWarning,
- "Comparison between bytearray and string", 1))
- return NULL;
+ if (!PyObject_CheckBuffer(self) || !PyObject_CheckBuffer(other)) {
+ if (PyUnicode_Check(self) || PyUnicode_Check(other)) {
+ if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) {
+ if (PyErr_WarnEx(PyExc_BytesWarning,
+ "Comparison between bytearray and string", 1))
+ return NULL;
+ }
}
-
Py_RETURN_NOTIMPLEMENTED;
}