Commit 11d29d3
committed
file.c: strrdirsep search from the back of the string for common encodings
`strrdirsep` quite innficiently search for the last separator from the front
of the string.
This is surprising but necessary because in Shift-JS, `0x5c` can
be the second byte of some multi-byte characters, as such it's
not possible to do a pure ASCII search. And it's even more costly
because for each character we need to do expensive checks to
handle this possibility.
However in the overwhelming majority of cases, paths are encoded
in UTF-8 or ASCII, so for these common encodings we can use the
more logical and efficient algorithm.
```
compare-ruby: ruby 4.1.0dev (2026-01-17T14:40:03Z master 00a3b71) +PRISM [arm64-darwin25]
built-ruby: ruby 4.1.0dev (2026-01-19T07:43:57Z file-dirname-lower.. a8d3535e5b) +PRISM [arm64-darwin25]
```
| |compare-ruby|built-ruby|
|:------|-----------:|---------:|
|long | 3.974M| 23.674M|
| | -| 5.96x|
|short | 15.281M| 29.034M|
| | -| 1.90x|1 parent 27bb162 commit 11d29d3
1 file changed
Lines changed: 44 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3693 | 3693 | | |
3694 | 3694 | | |
3695 | 3695 | | |
3696 | | - | |
3697 | 3696 | | |
3698 | 3697 | | |
3699 | 3698 | | |
| |||
3712 | 3711 | | |
3713 | 3712 | | |
3714 | 3713 | | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
| 3733 | + | |
| 3734 | + | |
| 3735 | + | |
| 3736 | + | |
| 3737 | + | |
3715 | 3738 | | |
3716 | 3739 | | |
3717 | 3740 | | |
| |||
5036 | 5059 | | |
5037 | 5060 | | |
5038 | 5061 | | |
| 5062 | + | |
| 5063 | + | |
| 5064 | + | |
| 5065 | + | |
| 5066 | + | |
| 5067 | + | |
| 5068 | + | |
| 5069 | + | |
| 5070 | + | |
5039 | 5071 | | |
5040 | 5072 | | |
5041 | 5073 | | |
| |||
5048 | 5080 | | |
5049 | 5081 | | |
5050 | 5082 | | |
5051 | | - | |
| 5083 | + | |
5052 | 5084 | | |
5053 | 5085 | | |
5054 | 5086 | | |
| |||
5082 | 5114 | | |
5083 | 5115 | | |
5084 | 5116 | | |
5085 | | - | |
| 5117 | + | |
| 5118 | + | |
| 5119 | + | |
| 5120 | + | |
| 5121 | + | |
| 5122 | + | |
5086 | 5123 | | |
5087 | 5124 | | |
5088 | 5125 | | |
5089 | 5126 | | |
5090 | 5127 | | |
5091 | 5128 | | |
5092 | 5129 | | |
| 5130 | + | |
5093 | 5131 | | |
5094 | | - | |
| 5132 | + | |
5095 | 5133 | | |
5096 | 5134 | | |
5097 | 5135 | | |
5098 | 5136 | | |
5099 | | - | |
| 5137 | + | |
5100 | 5138 | | |
5101 | 5139 | | |
5102 | 5140 | | |
5103 | 5141 | | |
5104 | | - | |
| 5142 | + | |
5105 | 5143 | | |
5106 | 5144 | | |
5107 | 5145 | | |
| |||
0 commit comments