mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #27704: Optimized creating bytes and bytearray from byte-like objects
and iterables. Speed up to 3 times for short objects. Original patch by Naoki Inada.
This commit is contained in:
parent
d00342347e
commit
eb24988962
3 changed files with 20 additions and 20 deletions
|
@ -2563,17 +2563,15 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
return NULL;
|
||||
}
|
||||
/* Is it an integer? */
|
||||
size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
|
||||
if (size == -1 && PyErr_Occurred()) {
|
||||
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||
if (PyIndex_Check(x)) {
|
||||
size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
|
||||
if (size == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
PyErr_Clear();
|
||||
}
|
||||
else if (size < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
}
|
||||
if (size < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return NULL;
|
||||
}
|
||||
new = _PyBytes_FromSize(size, 1);
|
||||
if (new == NULL)
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue