]> granicus.if.org Git - python/commitdiff
Issue #14687: Optimize str%args
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 1 May 2012 22:29:36 +0000 (00:29 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 1 May 2012 22:29:36 +0000 (00:29 +0200)
 * formatfloat() uses unicode_fromascii() instead of PyUnicode_DecodeASCII()
   to not have to check characters, we know that it is really ASCII
 * Use PyUnicode_FromOrdinal() instead of _PyUnicode_FromUCS4() to format
   a character: if avoids a call to ucs4lib_find_max_char() to compute
   the maximum character (whereas we already know it, it is just the character
   itself)

Objects/unicodeobject.c

index 18bc07f908d2b6a3737df78336513722ec8f3492..95993e879fb4f6b8563985bcb5d0f227c2b1384e 100644 (file)
@@ -13431,7 +13431,7 @@ formatfloat(PyObject *v, int flags, int prec, int type)
                               (flags & F_ALT) ? Py_DTSF_ALT : 0, NULL);
     if (p == NULL)
         return NULL;
-    result = PyUnicode_DecodeASCII(p, strlen(p), NULL);
+    result = unicode_fromascii((unsigned char*)p, strlen(p));
     PyMem_Free(p);
     return result;
 }
@@ -13947,7 +13947,7 @@ PyUnicode_Format(PyObject *format, PyObject *args)
                 Py_UCS4 ch = formatchar(v);
                 if (ch == (Py_UCS4) -1)
                     goto onError;
-                temp = _PyUnicode_FromUCS4(&ch, 1);
+                temp = PyUnicode_FromOrdinal(ch);
                 break;
             }