]> granicus.if.org Git - python/commitdiff
Issue #14687: Optimize str%tuple for the "%(name)s" syntax
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 2 May 2012 23:44:59 +0000 (01:44 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 2 May 2012 23:44:59 +0000 (01:44 +0200)
Avoid an useless and expensive call to PyUnicode_READ().

Objects/unicodeobject.c

index cf0bab9462caf43df551cbdc9373251cfd1365e7..e22fcfd02b126b5ea4254dc179aa9445a01c5f0c 100644 (file)
@@ -13737,9 +13737,10 @@ PyUnicode_Format(PyObject *format, PyObject *args)
                 keystart = fmtpos;
                 /* Skip over balanced parentheses */
                 while (pcount > 0 && --fmtcnt >= 0) {
-                    if (PyUnicode_READ(fmtkind, fmt, fmtpos) == ')')
+                    c = PyUnicode_READ(fmtkind, fmt, fmtpos);
+                    if (c == ')')
                         --pcount;
-                    else if (PyUnicode_READ(fmtkind, fmt, fmtpos) == '(')
+                    else if (c == '(')
                         ++pcount;
                     fmtpos++;
                 }