mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
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.
This commit is contained in:
parent
5ef53a88f3
commit
313467efdc
3 changed files with 14 additions and 33 deletions
|
|
@ -1538,36 +1538,19 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
|
|||
int c;
|
||||
Py_ssize_t len_a, len_b;
|
||||
Py_ssize_t min_len;
|
||||
int rc;
|
||||
|
||||
/* Make sure both arguments are strings. */
|
||||
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
|
||||
if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) {
|
||||
rc = PyObject_IsInstance((PyObject*)a,
|
||||
(PyObject*)&PyUnicode_Type);
|
||||
if (!rc)
|
||||
rc = PyObject_IsInstance((PyObject*)b,
|
||||
(PyObject*)&PyUnicode_Type);
|
||||
if (rc < 0)
|
||||
return NULL;
|
||||
if (rc) {
|
||||
if (PyUnicode_Check(a) || PyUnicode_Check(b)) {
|
||||
if (PyErr_WarnEx(PyExc_BytesWarning,
|
||||
"Comparison between bytes and string", 1))
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
rc = PyObject_IsInstance((PyObject*)a,
|
||||
(PyObject*)&PyLong_Type);
|
||||
if (!rc)
|
||||
rc = PyObject_IsInstance((PyObject*)b,
|
||||
(PyObject*)&PyLong_Type);
|
||||
if (rc < 0)
|
||||
if (PyLong_Check(a) || PyLong_Check(b)) {
|
||||
if (PyErr_WarnEx(PyExc_BytesWarning,
|
||||
"Comparison between bytes and int", 1))
|
||||
return NULL;
|
||||
if (rc) {
|
||||
if (PyErr_WarnEx(PyExc_BytesWarning,
|
||||
"Comparison between bytes and int", 1))
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
Py_RETURN_NOTIMPLEMENTED;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue