Commit a3e19f1
Don't make slice copies in TokenList._token_matching().
Since we are working with indexes anyway, don't bother calling
enumerate() with a slice from self.tokens (which requires copying
memory). Instead, just generate the indexes using range() and use
normal indexing to access the desired tokens.
The old behavior resulted in quadratic runtime with respect to the
number of tokens, which significantly impacted performance for
statements with very large numbers of tokens.
With the new behavior, the runtime is now linear with respect to the
number of tokens.1 parent 4073b56 commit a3e19f1
1 file changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
244 | 247 | | |
245 | 248 | | |
246 | 249 | | |
| |||
0 commit comments