diff Python/formatter_unicode.c @ 87263:d1ca05428c38

Add _PyUnicodeWriter_WriteASCIIString() function
author Victor Stinner <victor.stinner@gmail.com>
date Tue, 19 Nov 2013 12:54:53 +0100
parents 0872257752c2
children
line wrap: on
line diff
--- a/Python/formatter_unicode.c	Tue Nov 19 12:09:00 2013 +0100
+++ b/Python/formatter_unicode.c	Tue Nov 19 12:54:53 2013 +0100
@@ -1053,6 +1053,17 @@
         n_digits += 1;
     }
 
+    if (format->sign != '+' && format->sign != ' '
+        && format->width == -1
+        && format->type != 'n'
+        && !format->thousands_separators)
+    {
+        /* Fast path */
+        result = _PyUnicodeWriter_WriteASCIIString(writer, buf, n_digits);
+        PyMem_Free(buf);
+        return result;
+    }
+
     /* Since there is no unicode version of PyOS_double_to_string,
        just use the 8 bit version and then convert to unicode. */
     unicode_tmp = _PyUnicode_FromASCII(buf, n_digits);
@@ -1060,17 +1071,6 @@
     if (unicode_tmp == NULL)
         goto done;
 
-    if (format->sign != '+' && format->sign != ' '
-        && format->width == -1
-        && format->type != 'n'
-        && !format->thousands_separators)
-    {
-        /* Fast path */
-        result = _PyUnicodeWriter_WriteStr(writer, unicode_tmp);
-        Py_DECREF(unicode_tmp);
-        return result;
-    }
-
     /* Is a sign character present in the output?  If so, remember it
        and skip it */
     index = 0;