Commit 335eeb4
authored
Improve Regex performance (in particular RegexOptions.Compiled) (dotnet#271)
* Avoid generating timeout checks for infinite timeouts
* Use Ldc_I4_X for Ldc when applicable
* Use ToLowerInvariant for invariant mode
* Remove unnecessary virtual-ness of some internal methods
* Clean up CompiledRegexRunner
* Lazily allocate RegexCharClass._categories
* Avoid negative numbers in generated names
* Optimize Is{ECMA}WordChar
* Optimize common CharInClass calls
* Clean up RegexCompiler.cs
* Add more RegexOptions.Compiled tests
* Replace RegexParser.s_category byte[] with a span
* Avoid delegate allocations each time CreateInstance is called
* Replace CharUnicodeInfo.GetUnicodeCategory w/ char's version
It has a fast path for ASCII.
* Clean up stackallocs
* Remove an unnecessary box
* Avoid string allocation for negated category
* Simplify tests
* Make low-hanging fruit allocation reduction
e.g. avoiding allocating a range list if a class contains only categories, avoiding some intermediary strings, avoiding some delegate allocations for sorting, etc.
* More code cleanup
* Use String.IndexOf in RegexParser.Unescape1 parent 3952a34 commit 335eeb4
26 files changed
Lines changed: 2178 additions & 2454 deletions
File tree
- src/libraries/System.Text.RegularExpressions
- src/System/Text/RegularExpressions
- tests
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
Lines changed: 7 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 20 | + | |
26 | 21 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 22 | + | |
31 | 23 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 24 | + | |
36 | 25 | | |
37 | 26 | | |
Lines changed: 8 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
17 | 15 | | |
18 | | - | |
| 16 | + | |
19 | 17 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
23 | 21 | | |
24 | 22 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 23 | + | |
34 | 24 | | |
35 | 25 | | |
Lines changed: 1 addition & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 45 | + | |
55 | 46 | | |
56 | 47 | | |
57 | 48 | | |
| |||
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/GroupCollection.cs
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
| |||
Lines changed: 16 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 92 | + | |
102 | 93 | | |
103 | 94 | | |
104 | 95 | | |
| |||
127 | 118 | | |
128 | 119 | | |
129 | 120 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 121 | + | |
| 122 | + | |
135 | 123 | | |
136 | | - | |
137 | 124 | | |
138 | 125 | | |
139 | 126 | | |
140 | | - | |
| 127 | + | |
141 | 128 | | |
142 | 129 | | |
143 | 130 | | |
| |||
180 | 167 | | |
181 | 168 | | |
182 | 169 | | |
183 | | - | |
| 170 | + | |
184 | 171 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 172 | + | |
189 | 173 | | |
190 | | - | |
| 174 | + | |
191 | 175 | | |
192 | 176 | | |
193 | 177 | | |
| |||
210 | 194 | | |
211 | 195 | | |
212 | 196 | | |
213 | | - | |
| 197 | + | |
214 | 198 | | |
215 | 199 | | |
216 | 200 | | |
| |||
236 | 220 | | |
237 | 221 | | |
238 | 222 | | |
239 | | - | |
| 223 | + | |
240 | 224 | | |
241 | 225 | | |
242 | 226 | | |
243 | 227 | | |
244 | 228 | | |
245 | 229 | | |
246 | 230 | | |
247 | | - | |
| 231 | + | |
248 | 232 | | |
249 | 233 | | |
250 | 234 | | |
251 | 235 | | |
252 | 236 | | |
253 | 237 | | |
254 | 238 | | |
255 | | - | |
| 239 | + | |
256 | 240 | | |
257 | 241 | | |
258 | 242 | | |
| |||
264 | 248 | | |
265 | 249 | | |
266 | 250 | | |
267 | | - | |
| 251 | + | |
268 | 252 | | |
269 | 253 | | |
270 | 254 | | |
| |||
276 | 260 | | |
277 | 261 | | |
278 | 262 | | |
279 | | - | |
| 263 | + | |
280 | 264 | | |
281 | 265 | | |
282 | 266 | | |
| |||
334 | 318 | | |
335 | 319 | | |
336 | 320 | | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
| 321 | + | |
347 | 322 | | |
348 | 323 | | |
349 | 324 | | |
| |||
381 | 356 | | |
382 | 357 | | |
383 | 358 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
| 359 | + | |
394 | 360 | | |
395 | 361 | | |
396 | 362 | | |
| |||
0 commit comments