Commit c044d1d
committed
[SwiftParser] Intern the whole source buffer for a full parse
748dde4 ([SwiftParser] Intern source text per parsed token) changed
parsing to intern each token's text individually instead of copying the
whole source buffer once, so a parsed tree no longer retains the source
buffer. That is important for incremental reparsing memory, but it
regressed full-parse performance: a full parse now copies the source in
as many pieces as there are tokens, each with its own bump-allocation
and memcpy, rather than in a single bulk copy.
For a full (non-incremental) parse, copy the whole source into the arena
once and lex over that copy. Parsed tokens then point directly into
arena-owned memory, so `internParsedTokenText` returns their text
unchanged instead of copying it, and the tree stays self-contained. An
incremental reparse keeps interning each re-lexed token individually, so
its new tree still references only the re-lexed spans and not the whole
buffer.
`ParsingRawSyntaxArena.internSourceBuffer` copies the buffer, records
its bounds, and returns the copy for `Parser` to lex over on a full
parse; `internParsedTokenText` returns text that lies within the copy
unchanged and copies anything else (e.g. synthesized tokens). Because
the copy is owned by the arena, a full parse needs no parser-owned
source copy, and nothing points into the caller's buffer once parsing
returns.1 parent b8e7d60 commit c044d1d
2 files changed
Lines changed: 54 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
248 | 252 | | |
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
256 | 259 | | |
257 | 260 | | |
258 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
205 | 216 | | |
206 | 217 | | |
207 | 218 | | |
208 | 219 | | |
209 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
210 | 243 | | |
211 | 244 | | |
212 | 245 | | |
213 | 246 | | |
214 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
215 | 251 | | |
216 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
217 | 256 | | |
218 | 257 | | |
219 | 258 | | |
| |||
0 commit comments