Skip to content

Commit b5c3ea3

Browse files
committed
Issue #14687: Optimize str%args
* 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)
1 parent cc1c146 commit b5c3ea3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13431,7 +13431,7 @@ formatfloat(PyObject *v, int flags, int prec, int type)
1343113431
(flags & F_ALT) ? Py_DTSF_ALT : 0, NULL);
1343213432
if (p == NULL)
1343313433
return NULL;
13434-
result = PyUnicode_DecodeASCII(p, strlen(p), NULL);
13434+
result = unicode_fromascii((unsigned char*)p, strlen(p));
1343513435
PyMem_Free(p);
1343613436
return result;
1343713437
}
@@ -13947,7 +13947,7 @@ PyUnicode_Format(PyObject *format, PyObject *args)
1394713947
Py_UCS4 ch = formatchar(v);
1394813948
if (ch == (Py_UCS4) -1)
1394913949
goto onError;
13950-
temp = _PyUnicode_FromUCS4(&ch, 1);
13950+
temp = PyUnicode_FromOrdinal(ch);
1395113951
break;
1395213952
}
1395313953

0 commit comments

Comments
 (0)