Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 47392:47ef9a806ce9 legacy-trunk
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Fri, 30 May 2008 18:10:04 +0000 |
| parents | 4fe192d48960 |
| children | 52294af4b663 |
line wrap: on
line diff
--- a/Objects/floatobject.c Fri May 30 07:54:16 2008 +0000 +++ b/Objects/floatobject.c Fri May 30 18:10:04 2008 +0000 @@ -14,9 +14,6 @@ #include <ieeefp.h> #endif -#include "formatter_string.h" - - #ifdef _OSF_SOURCE /* OSF1 5.1 doesn't make this available with XOPEN_SOURCE_EXTENDED defined */ extern int finite(double); @@ -1398,26 +1395,22 @@ if (!PyArg_ParseTuple(args, "O:__format__", &format_spec)) return NULL; if (PyBytes_Check(format_spec)) - return string_float__format__(self, args); + return _PyFloat_FormatAdvanced(self, + PyBytes_AS_STRING(format_spec), + PyBytes_GET_SIZE(format_spec)); if (PyUnicode_Check(format_spec)) { /* Convert format_spec to a str */ - PyObject *result = NULL; - PyObject *newargs = NULL; - PyObject *string_format_spec = NULL; + PyObject *result; + PyObject *str_spec = PyObject_Str(format_spec); - string_format_spec = PyObject_Str(format_spec); - if (string_format_spec == NULL) - goto done; + if (str_spec == NULL) + return NULL; - newargs = Py_BuildValue("(O)", string_format_spec); - if (newargs == NULL) - goto done; + result = _PyFloat_FormatAdvanced(self, + PyBytes_AS_STRING(str_spec), + PyBytes_GET_SIZE(str_spec)); - result = string_float__format__(self, newargs); - - done: - Py_XDECREF(string_format_spec); - Py_XDECREF(newargs); + Py_DECREF(str_spec); return result; } PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");
