diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-13 19:23:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 19:23:48 (GMT) |
commit | 9b6c60cbce4ac45e8ccd7934babff465e9769509 (patch) | |
tree | 973d37d42dfe1ce66303ad0cf658bb20870aa88e /Objects/longobject.c | |
parent | ce12629c84400c52734859e43b2386deb2b6da12 (diff) | |
download | cpython-9b6c60cbce4ac45e8ccd7934babff465e9769509.zip cpython-9b6c60cbce4ac45e8ccd7934babff465e9769509.tar.gz cpython-9b6c60cbce4ac45e8ccd7934babff465e9769509.tar.bz2 |
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%.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 6fd4feb..7437155 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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) { - 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; - } + assert(buffer != NULL); + + result = PyLong_FromString(buffer, &end, base); + if (end == NULL || (result != NULL && end == buffer + buflen)) { 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); |