Commits

Victor Stinner  committed 320759f

float fast-path

Fix also fast-path in str%args for sign

  • Participants
  • Parent commits 08704e6

Comments (0)

Files changed (2)

File Objects/unicodeobject.c

             case 'o':
             case 'x':
             case 'X':
-                if (PyLong_CheckExact(v) && width == -1 && prec == -1) {
+                if (PyLong_CheckExact(v)
+                    && width == -1 && prec == -1
+                    && !(flags & (F_SIGN | F_BLANK)))
+                {
                     /* Fast path */
                     switch(c)
                     {
                 goto onError;
             assert (PyUnicode_Check(temp));
 
-            if (width == -1 && prec == -1) {
+            if (width == -1 && prec == -1
+                && !(flags & (F_SIGN | F_BLANK)))
+            {
                 /* Fast path */
                 if (_PyUnicodeWriter_WriteStr(&writer, temp) == -1)
                     goto onError;

File Python/formatter_unicode.c

     /* Since there is no unicode version of PyOS_double_to_string,
        just use the 8 bit version and then convert to unicode. */
     unicode_tmp = strtounicode(buf, n_digits);
+    PyMem_Free(buf);
     if (unicode_tmp == NULL)
         goto done;
-    index = 0;
+
+    if (format->sign != '+' && format->sign != ' '
+        && format->width == -1
+        && format->type != 'n')
+    {
+        /* 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;
     if (PyUnicode_READ_CHAR(unicode_tmp, index) == '-') {
         sign_char = '-';
         ++index;
                          &locale, 0);
 
 done:
-    PyMem_Free(buf);
     Py_DECREF(unicode_tmp);
     free_locale_info(&locale);
     return result;
     NumberFieldWidths re_spec;
     NumberFieldWidths im_spec;
     int flags = 0;
-    int result;
+    int result = -1;
     Py_UCS4 maxchar = 127;
     enum PyUnicode_Kind rkind;
     void *rdata;