mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
bpo-31979: Simplify transforming decimals to ASCII (#4336)
in int(), float() and complex() parsers. This also speeds up parsing non-ASCII numbers by around 20%.
This commit is contained in:
parent
ce12629c84
commit
9b6c60cbce
7 changed files with 63 additions and 139 deletions
|
|
@ -2509,21 +2509,18 @@ PyLong_FromUnicodeObject(PyObject *u, int base)
|
|||
asciidig = _PyUnicode_TransformDecimalAndSpaceToASCII(u);
|
||||
if (asciidig == NULL)
|
||||
return NULL;
|
||||
assert(PyUnicode_IS_ASCII(asciidig));
|
||||
/* Simply get a pointer to existing ASCII characters. */
|
||||
buffer = PyUnicode_AsUTF8AndSize(asciidig, &buflen);
|
||||
if (buffer == NULL) {
|
||||
assert(buffer != NULL);
|
||||
|
||||
result = PyLong_FromString(buffer, &end, base);
|
||||
if (end == NULL || (result != NULL && end == buffer + buflen)) {
|
||||
Py_DECREF(asciidig);
|
||||
if (!PyErr_ExceptionMatches(PyExc_UnicodeEncodeError))
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
result = PyLong_FromString(buffer, &end, base);
|
||||
if (end == NULL || (result != NULL && end == buffer + buflen)) {
|
||||
Py_DECREF(asciidig);
|
||||
return result;
|
||||
}
|
||||
Py_DECREF(asciidig);
|
||||
Py_XDECREF(result);
|
||||
return result;
|
||||
}
|
||||
Py_DECREF(asciidig);
|
||||
Py_XDECREF(result);
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"invalid literal for int() with base %d: %.200R",
|
||||
base, u);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue