Commit 0ae5593
committed
Resolve #17 optimize use of '^' / '\A'
The problem was that a regular expression like "^x" would take linear time to is_match a string "aaa...." when all it needed to do was check the first character then bail out. This commit makes it so if the regex begins with '^' (without multiline) or '\A', then it stops iterating over characters as soon as there are no possible matches. Benchmarks: dynamic: anchored_literal_long_non_match: 7492 ns/iter => 435 ns/iter anchored_literal_short_non_match: 917 ns/iter => 431 ns/iter native: anchored_literal_long_non_match: 5020 ns/iter => 50 ns/iter anchored_literal_short_non_match: 375 ns/iter => 50 ns/iter1 parent 588319a commit 0ae5593
2 files changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
194 | 199 | | |
195 | 200 | | |
196 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
147 | 153 | | |
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
151 | 157 | | |
152 | | - | |
| 158 | + | |
153 | 159 | | |
154 | 160 | | |
155 | 161 | | |
| |||
0 commit comments