diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-12 07:21:14 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-12 07:21:14 (GMT) |
commit | 25885d1dc588ce82f4b05899705fb54cb8704a35 (patch) | |
tree | b0398b71d96dae93c91dd4d7e1a58baeb14d3e39 | |
parent | 871639a6d5ceb1cfb858c8c6ad000885135c2733 (diff) | |
download | cpython-25885d1dc588ce82f4b05899705fb54cb8704a35.zip cpython-25885d1dc588ce82f4b05899705fb54cb8704a35.tar.gz cpython-25885d1dc588ce82f4b05899705fb54cb8704a35.tar.bz2 |
Issue #27005: Optimized the float.fromhex() class method for exact float.
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/floatobject.c | 11 |
2 files changed, 8 insertions, 6 deletions
@@ -10,6 +10,9 @@ Release date: tba Core and Builtins ----------------- +- Issue #27005: Optimized the float.fromhex() class method for exact float. + It is now 2 times faster. + - Issue #18531: Single var-keyword argument of dict subtype was passed unscathed to the C-defined function. Now it is converted to exact dict. diff --git a/Objects/floatobject.c b/Objects/floatobject.c index eb60659..f640dd3 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1195,7 +1195,7 @@ Return a hexadecimal representation of a floating-point number.\n\ static PyObject * float_fromhex(PyObject *cls, PyObject *arg) { - PyObject *result_as_float, *result; + PyObject *result; double x; long exp, top_exp, lsb, key_digit; char *s, *coeff_start, *s_store, *coeff_end, *exp_start, *s_end; @@ -1410,11 +1410,10 @@ float_fromhex(PyObject *cls, PyObject *arg) s++; if (s != s_end) goto parse_error; - result_as_float = Py_BuildValue("(d)", negate ? -x : x); - if (result_as_float == NULL) - return NULL; - result = PyObject_CallObject(cls, result_as_float); - Py_DECREF(result_as_float); + result = PyFloat_FromDouble(negate ? -x : x); + if (cls != (PyObject *)&PyFloat_Type && result != NULL) { + Py_SETREF(result, PyObject_CallFunctionObjArgs(cls, result)); + } return result; overflow_error: |