Commit b2ff013
committed
Apply the rest of the review: fewer allocations, less repetition
Efficiency, measured with alloc profiles over the corpus tests:
- internal/dump dominated the harness, not the parser. It rebuilt each
node type's field layout per instance and formatted every scalar
through fmt. The layout is cached per type and the leaves go straight
to the builder; TestRoundTrip drops from 1.5s to 0.55s.
- regenerate-parse started and tore down a pool of oracle processes per
script, forking a few thousand times over a run. One pool for the
whole run takes regeneration from 19s to 2.5s, corpus byte-identical.
- parseTypeToken built a slice and joined it for every column type, when
a type is almost always one word.
- The %fallback set and the infix operator table are Kind-indexed arrays
rather than maps; both are consulted per token.
- Children() allocates only when a node has children, and the parser's
named-parameter map only when there is a named parameter.
Repetition:
- parseOperators stated the precedence guard seventeen times, once per
case, with half the operators tabled and half inline. One table, one
guard; the operators with syntax of their own keep their cases.
- The trigger body re-implemented UPDATE, INSERT and DELETE. It shares
their cores now, so the three real differences -- no WITH, where_opt
instead of where_opt_ret, no DEFAULT VALUES -- are visible lines
rather than absences.
- CreateTableStmt held Options and WithoutOpt as index-parallel slices,
an invariant only the parser knew and only the renderer could break.
- 27 Children() methods spelled out the same append loop; writeOnConflict
and writeOrConflict differed only in a keyword.
And the shift-then-decide rule that five comments were each re-arguing
is now stated once in the package doc.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JzBeCg7rjweVW3uGPg5G7T1 parent 39dadb4 commit b2ff013
17 files changed
Lines changed: 363 additions & 370 deletions
File tree
- ast
- cmd
- difftest
- regenerate-parse
- internal
- dump
- tclextract
- parser
- testdata/ast
- token
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
22 | 33 | | |
23 | 34 | | |
24 | 35 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
135 | | - | |
136 | | - | |
137 | | - | |
| 138 | + | |
138 | 139 | | |
139 | | - | |
140 | | - | |
141 | | - | |
| 140 | + | |
142 | 141 | | |
143 | 142 | | |
144 | 143 | | |
| |||
179 | 178 | | |
180 | 179 | | |
181 | 180 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 181 | + | |
| 182 | + | |
188 | 183 | | |
189 | 184 | | |
190 | 185 | | |
| |||
228 | 223 | | |
229 | 224 | | |
230 | 225 | | |
231 | | - | |
232 | | - | |
233 | | - | |
| 226 | + | |
234 | 227 | | |
235 | 228 | | |
236 | 229 | | |
| |||
249 | 242 | | |
250 | 243 | | |
251 | 244 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 245 | + | |
255 | 246 | | |
256 | 247 | | |
257 | 248 | | |
| |||
287 | 278 | | |
288 | 279 | | |
289 | 280 | | |
290 | | - | |
291 | | - | |
292 | | - | |
| 281 | + | |
293 | 282 | | |
294 | | - | |
295 | | - | |
296 | | - | |
| 283 | + | |
297 | 284 | | |
298 | 285 | | |
299 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 44 | + | |
47 | 45 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 46 | + | |
| 47 | + | |
54 | 48 | | |
55 | 49 | | |
56 | 50 | | |
| |||
69 | 63 | | |
70 | 64 | | |
71 | 65 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 66 | + | |
75 | 67 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 68 | + | |
79 | 69 | | |
80 | 70 | | |
81 | 71 | | |
| |||
92 | 82 | | |
93 | 83 | | |
94 | 84 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 85 | + | |
98 | 86 | | |
99 | 87 | | |
100 | 88 | | |
| |||
123 | 111 | | |
124 | 112 | | |
125 | 113 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 114 | + | |
| 115 | + | |
132 | 116 | | |
133 | | - | |
134 | | - | |
135 | | - | |
| 117 | + | |
136 | 118 | | |
137 | 119 | | |
138 | 120 | | |
| |||
155 | 137 | | |
156 | 138 | | |
157 | 139 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 140 | + | |
161 | 141 | | |
162 | 142 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 295 | + | |
| 296 | + | |
301 | 297 | | |
302 | 298 | | |
303 | 299 | | |
| |||
314 | 310 | | |
315 | 311 | | |
316 | 312 | | |
317 | | - | |
318 | | - | |
319 | | - | |
| 313 | + | |
320 | 314 | | |
321 | 315 | | |
322 | 316 | | |
| |||
375 | 369 | | |
376 | 370 | | |
377 | 371 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
| 372 | + | |
| 373 | + | |
384 | 374 | | |
385 | 375 | | |
386 | 376 | | |
| |||
448 | 438 | | |
449 | 439 | | |
450 | 440 | | |
451 | | - | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
452 | 444 | | |
453 | | - | |
| 445 | + | |
454 | 446 | | |
455 | 447 | | |
456 | 448 | | |
457 | 449 | | |
458 | 450 | | |
459 | 451 | | |
460 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
0 commit comments