Commit b2c23f1
committed
Use stack buffers for repr-mode float and complex formatting
float_repr() and complex_repr() now format into stack buffers via
_Py_double_repr_buffered() and call _PyUnicode_FromASCII() directly,
eliminating the per-call PyMem_Malloc/strlen/PyMem_Free round-trip
(and PyUnicode_FromFormat for complex).
float.__format__ and complex.__format__ short-circuit an empty format
spec to the corresponding repr for exact instances, skipping the
_PyUnicodeWriter setup.
format_float_internal() in unicode_formatter.c uses a stack buffer
when the effective format code is 'r' (no type code given), avoiding
the PyOS_double_to_string heap allocation for f"{x:>10}" and similar.
The write-only float_type local is removed; the equivalent dead
re_float_type/im_float_type in format_complex_internal are removed
while here.
The legacy _PY_SHORT_FLOAT_REPR == 0 paths are preserved under
#else for non-IEEE-754 platforms.1 parent 3cb40da commit b2c23f1
3 files changed
Lines changed: 80 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
573 | 574 | | |
574 | 575 | | |
575 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
576 | 606 | | |
577 | 607 | | |
578 | 608 | | |
579 | | - | |
580 | 609 | | |
581 | 610 | | |
582 | 611 | | |
| |||
625 | 654 | | |
626 | 655 | | |
627 | 656 | | |
| 657 | + | |
628 | 658 | | |
629 | 659 | | |
630 | 660 | | |
| |||
913 | 943 | | |
914 | 944 | | |
915 | 945 | | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
916 | 953 | | |
917 | 954 | | |
918 | 955 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
342 | 350 | | |
343 | 351 | | |
344 | 352 | | |
| |||
351 | 359 | | |
352 | 360 | | |
353 | 361 | | |
| 362 | + | |
354 | 363 | | |
355 | 364 | | |
356 | 365 | | |
| |||
1729 | 1738 | | |
1730 | 1739 | | |
1731 | 1740 | | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1732 | 1747 | | |
1733 | 1748 | | |
1734 | 1749 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
1375 | 1376 | | |
1376 | 1377 | | |
1377 | 1378 | | |
| 1379 | + | |
1378 | 1380 | | |
1379 | 1381 | | |
1380 | 1382 | | |
| |||
1390 | 1392 | | |
1391 | 1393 | | |
1392 | 1394 | | |
1393 | | - | |
1394 | 1395 | | |
1395 | 1396 | | |
1396 | 1397 | | |
| |||
1440 | 1441 | | |
1441 | 1442 | | |
1442 | 1443 | | |
1443 | | - | |
1444 | | - | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
1448 | 1461 | | |
1449 | 1462 | | |
1450 | 1463 | | |
| |||
1462 | 1475 | | |
1463 | 1476 | | |
1464 | 1477 | | |
1465 | | - | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
1466 | 1481 | | |
1467 | 1482 | | |
1468 | 1483 | | |
1469 | 1484 | | |
1470 | 1485 | | |
1471 | 1486 | | |
1472 | | - | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
1473 | 1490 | | |
1474 | 1491 | | |
1475 | 1492 | | |
| |||
1556 | 1573 | | |
1557 | 1574 | | |
1558 | 1575 | | |
1559 | | - | |
1560 | | - | |
1561 | 1576 | | |
1562 | 1577 | | |
1563 | 1578 | | |
| |||
1628 | 1643 | | |
1629 | 1644 | | |
1630 | 1645 | | |
1631 | | - | |
| 1646 | + | |
1632 | 1647 | | |
1633 | 1648 | | |
1634 | 1649 | | |
1635 | | - | |
| 1650 | + | |
1636 | 1651 | | |
1637 | 1652 | | |
1638 | 1653 | | |
| |||
0 commit comments