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%.
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 4bcf2ce..2c886c7 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -914,10 +914,10 @@
if (s_buffer == NULL) {
return NULL;
}
+ assert(PyUnicode_IS_ASCII(s_buffer));
+ /* Simply get a pointer to existing ASCII characters. */
s = PyUnicode_AsUTF8AndSize(s_buffer, &len);
- if (s == NULL) {
- goto exit;
- }
+ assert(s != NULL);
}
else {
PyErr_Format(PyExc_TypeError,
@@ -928,7 +928,6 @@
result = _Py_string_to_number_with_underscores(s, len, "complex", v, type,
complex_from_string_inner);
- exit:
Py_DECREF(s_buffer);
return result;
}