Commit 680b1a8
authored
Fix performance regression in split by avoiding allocating substring per char (#237)
This PR fixes a performance regression from #227 /
4c85bde which I overlooked in review:
When generalizing the optimized non-Pattern-based split code, that
commit introduced a `.substring()` on each character, producing tons of
garbage.
Instead, I think we can do a `.startsWith(splitPattern, i)`: this should
be much faster because it will avoid unnecessary garbage string creation
(plus I'm pretty sure that `startsWith` is optimized in modern JDKs).
I also removed the use of `breakable` and replaced it with an update to
the `while` condition.1 parent f5bf391 commit 680b1a8
1 file changed
Lines changed: 9 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
642 | 641 | | |
643 | 642 | | |
644 | 643 | | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
656 | 653 | | |
657 | 654 | | |
658 | 655 | | |
| |||
0 commit comments