mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
Issue #15609: Optimize str%args for integer argument
- Use _PyLong_FormatWriter() instead of formatlong() when possible, to avoid a temporary buffer - Enable the fast path when width is smaller or equals to the length, and when the precision is bigger or equals to the length - Add unit tests! - formatlong() uses PyUnicode_Resize() instead of _PyUnicode_FromASCII() to resize the output string
This commit is contained in:
parent
fd0d3e5d25
commit
621ef3d84f
3 changed files with 119 additions and 68 deletions
|
|
@ -307,6 +307,22 @@ class FormatTest(unittest.TestCase):
|
|||
finally:
|
||||
locale.setlocale(locale.LC_ALL, oldloc)
|
||||
|
||||
@support.cpython_only
|
||||
def test_optimisations(self):
|
||||
text = "abcde" # 5 characters
|
||||
|
||||
self.assertIs("%s" % text, text)
|
||||
self.assertIs("%.5s" % text, text)
|
||||
self.assertIs("%.10s" % text, text)
|
||||
self.assertIs("%1s" % text, text)
|
||||
self.assertIs("%5s" % text, text)
|
||||
|
||||
self.assertIs("{0}".format(text), text)
|
||||
self.assertIs("{0:s}".format(text), text)
|
||||
self.assertIs("{0:.5s}".format(text), text)
|
||||
self.assertIs("{0:.10s}".format(text), text)
|
||||
self.assertIs("{0:1s}".format(text), text)
|
||||
self.assertIs("{0:5s}".format(text), text)
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue