mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Move the codec decode type checks to bytes/bytearray.decode().
Use faster PyUnicode_FromEncodedObject() for bytes/bytearray.decode(). Add new PyCodec_KnownEncoding() API. Add new PyUnicode_AsDecodedUnicode() and PyUnicode_AsEncodedUnicode() APIs. Add missing PyUnicode_AsDecodedObject() to unicodeobject.h Fix punicode codec to also work on memoryviews.
This commit is contained in:
parent
4efb518185
commit
b2750b5d33
8 changed files with 171 additions and 41 deletions
|
|
@ -725,7 +725,7 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
|
|||
"string argument without an encoding");
|
||||
return -1;
|
||||
}
|
||||
encoded = PyCodec_Encode(arg, encoding, errors);
|
||||
encoded = PyUnicode_AsEncodedString(arg, encoding, errors);
|
||||
if (encoded == NULL)
|
||||
return -1;
|
||||
assert(PyBytes_Check(encoded));
|
||||
|
|
@ -2854,7 +2854,7 @@ bytes_decode(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
if (encoding == NULL)
|
||||
encoding = PyUnicode_GetDefaultEncoding();
|
||||
return PyCodec_Decode(self, encoding, errors);
|
||||
return PyUnicode_FromEncodedObject(self, encoding, errors);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(alloc_doc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue