Commit d0b93b3
committed
Faster string reversal when source/dest buffers are distinct
`pp_reverse()` has traditionally operated on a single string buffer,
reversing it in place.
When `pp_reverse()` takes a single SV argument, whose buffer cannot be
swiped by `sv_setsv_flags()`, a straight copy of the buffer is taken
and then that is reversed. In such cases, two complete passes over the
entire string are needed to reverse a non-UTF8 string, and reversing a
UTF8 string takes three complete passes.
This commit enables `pp_reverse()` to apply the "swipe" test itself
and, for straightforward copy cases, to avoid calling `sv_setsv_flags()`.
Instead, it does the work of preparing the `TARG` SV and reverse copies
the string (UTF8 or otherwise) in a single pass.
The performance improvement will vary by compiler and CPU. With gcc 12.2.0
on Linux running on "znver3" hardware, performance for both UTF8 and
non-UTF8 strings approximately doubled. Using clang-11 instead on the same
machine gave a fivefold improvement for the non-UTF8 case.1 parent 84fa6b0 commit d0b93b3
1 file changed
+79
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6603 | 6603 | | |
6604 | 6604 | | |
6605 | 6605 | | |
6606 | | - | |
6607 | | - | |
| 6606 | + | |
6608 | 6607 | | |
6609 | 6608 | | |
6610 | 6609 | | |
| |||
6613 | 6612 | | |
6614 | 6613 | | |
6615 | 6614 | | |
6616 | | - | |
6617 | | - | |
6618 | | - | |
6619 | 6615 | | |
6620 | | - | |
6621 | | - | |
| 6616 | + | |
| 6617 | + | |
| 6618 | + | |
| 6619 | + | |
| 6620 | + | |
| 6621 | + | |
| 6622 | + | |
| 6623 | + | |
| 6624 | + | |
| 6625 | + | |
| 6626 | + | |
| 6627 | + | |
| 6628 | + | |
| 6629 | + | |
| 6630 | + | |
| 6631 | + | |
| 6632 | + | |
| 6633 | + | |
| 6634 | + | |
| 6635 | + | |
| 6636 | + | |
| 6637 | + | |
| 6638 | + | |
| 6639 | + | |
| 6640 | + | |
| 6641 | + | |
| 6642 | + | |
| 6643 | + | |
| 6644 | + | |
| 6645 | + | |
| 6646 | + | |
| 6647 | + | |
| 6648 | + | |
| 6649 | + | |
| 6650 | + | |
| 6651 | + | |
| 6652 | + | |
| 6653 | + | |
| 6654 | + | |
| 6655 | + | |
| 6656 | + | |
| 6657 | + | |
| 6658 | + | |
| 6659 | + | |
| 6660 | + | |
| 6661 | + | |
| 6662 | + | |
| 6663 | + | |
| 6664 | + | |
| 6665 | + | |
| 6666 | + | |
| 6667 | + | |
| 6668 | + | |
| 6669 | + | |
| 6670 | + | |
| 6671 | + | |
| 6672 | + | |
| 6673 | + | |
| 6674 | + | |
| 6675 | + | |
| 6676 | + | |
| 6677 | + | |
| 6678 | + | |
| 6679 | + | |
| 6680 | + | |
| 6681 | + | |
| 6682 | + | |
| 6683 | + | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
6622 | 6688 | | |
| 6689 | + | |
| 6690 | + | |
6623 | 6691 | | |
6624 | 6692 | | |
6625 | | - | |
| 6693 | + | |
| 6694 | + | |
6626 | 6695 | | |
| 6696 | + | |
6627 | 6697 | | |
6628 | 6698 | | |
6629 | 6699 | | |
| |||
6655 | 6725 | | |
6656 | 6726 | | |
6657 | 6727 | | |
6658 | | - | |
6659 | 6728 | | |
| 6729 | + | |
6660 | 6730 | | |
6661 | 6731 | | |
6662 | 6732 | | |
| |||
0 commit comments