Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: improve performance of SourceCode constructor (#8054)
When generating a list of tokens and comments, the `SourceCode` constructor previously concatenated the list of tokens and the list of comments, and sorted the result. For a file with `n` tokens and `n` comments, this takes `O(nlog(n))` time. However, since the token and comment lists are already sorted, they can be merged in `O(n)` time. The performance impact of this change is most noticable on large files, since they have a large number of tokens. When linting [test-data.js](https://gist.github.com/mysticatea/2fca6bc8c2194f75e4808a884a1e351a) (48000 lines) with no rules enabled, this improved overall performance by about 20%.
- Loading branch information