Commit 7e0e998
committed
rb_file_join_fastpath: optimize searching for separators
`chompdirsep` searches from the start of the string each time, which
perhaps is necessary for certain encodings (not even sure?) but for
the common encodings it's very wasteful. Instead we can start from the
back of the string and only compare one or two characters in most cases.
Also replace `StringValueCStr` for the simpler `rb_str_null_check`
as we only care about whether the string contains `NULL` bytes, we
don't care whether it is NULL terminated or not.
We also only check the final string for NULLs.
```
compare-ruby: ruby 4.1.0dev (2026-01-17T14:40:03Z master 00a3b71) +PRISM [arm64-darwin25]
built-ruby: ruby 4.1.0dev (2026-01-18T12:55:15Z spedup-file-join 5948e92e03) +PRISM [arm64-darwin25]
warming up....
| |compare-ruby|built-ruby|
|:-------------|-----------:|---------:|
|two_strings | 2.477M| 19.317M|
| | -| 7.80x|
|many_strings | 547.577k| 10.298M|
| | -| 18.81x|
|array | 515.280k| 523.291k|
| | -| 1.02x|
|mixed | 621.840k| 635.422k|
| | -| 1.02x|
```1 parent 6cd4549 commit 7e0e998
3 files changed
+44
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3714 | 3714 | | |
3715 | 3715 | | |
3716 | 3716 | | |
3717 | | - | |
3718 | | - | |
3719 | | - | |
3720 | | - | |
3721 | | - | |
3722 | | - | |
3723 | | - | |
3724 | | - | |
3725 | | - | |
3726 | | - | |
3727 | | - | |
3728 | | - | |
3729 | | - | |
3730 | | - | |
3731 | | - | |
3732 | | - | |
3733 | 3717 | | |
3734 | 3718 | | |
3735 | 3719 | | |
| |||
5374 | 5358 | | |
5375 | 5359 | | |
5376 | 5360 | | |
5377 | | - | |
5378 | 5361 | | |
5379 | 5362 | | |
5380 | | - | |
5381 | | - | |
5382 | | - | |
| 5363 | + | |
| 5364 | + | |
| 5365 | + | |
| 5366 | + | |
| 5367 | + | |
| 5368 | + | |
| 5369 | + | |
| 5370 | + | |
| 5371 | + | |
| 5372 | + | |
| 5373 | + | |
5383 | 5374 | | |
5384 | | - | |
| 5375 | + | |
| 5376 | + | |
5385 | 5377 | | |
5386 | 5378 | | |
5387 | 5379 | | |
| |||
5391 | 5383 | | |
5392 | 5384 | | |
5393 | 5385 | | |
5394 | | - | |
| 5386 | + | |
5395 | 5387 | | |
5396 | 5388 | | |
| 5389 | + | |
5397 | 5390 | | |
5398 | 5391 | | |
5399 | 5392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2902 | 2902 | | |
2903 | 2903 | | |
2904 | 2904 | | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
2905 | 2933 | | |
2906 | 2934 | | |
2907 | 2935 | | |
| |||
0 commit comments