Make line_col faster.#229
Merged
bors[bot] merged 2 commits intosoftdevteam:masterfrom Jan 8, 2021
Merged
Conversation
Member
|
bors r+ |
bors Bot
added a commit
that referenced
this pull request
Jan 8, 2021
229: Make line_col faster. r=ptersilie a=ltratt `line_col` was previously a linear search that called another function that does a linear search. This PR changes the first linear search into a binary search (b62cab2) and removes the second linear search entirely (2d61edb). This speeds up the easy bits of `line_col` significantly, moving us from `O(4n + x)` into `O(log_n + x)` where `n` is the number of lines in the file and `x` is whatever the cost to calculate the character offset from a line containing a string of bytes. Alas, this second thing is probably impossible to speed-up given that we're dealing with UTF-8. Still, this PR does at least address the most obviously egregious inefficiencies in `line_col` and it does so while decreasing the lines of code (allowing for the fact that I've added three lines of comments)! Co-authored-by: Laurence Tratt <laurie@tratt.net>
Contributor
|
Build failed: |
Member
Author
|
96f2ebc should fix the bors error and will need squashing. bors try |
Contributor
tryBuild succeeded: |
Member
|
Please squash. |
This reduces the amount of work `line_col` has to do, as we can infer the same information that `span_lines_str` has to calculate from scratch.
96f2ebc to
16721bf
Compare
Member
Author
|
Squashed. |
Member
|
bors r+ |
Contributor
|
Build succeeded: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
line_colwas previously a linear search that called another function that does a linear search. This PR changes the first linear search into a binary search (b62cab2) and removes the second linear search entirely (2d61edb).This speeds up the easy bits of
line_colsignificantly, moving us fromO(4n + x)intoO(log_n + x)wherenis the number of lines in the file andxis whatever the cost to calculate the character offset from a line containing a string of bytes. Alas, this second thing is probably impossible to speed-up given that we're dealing with UTF-8. Still, this PR does at least address the most obviously egregious inefficiencies inline_coland it does so while decreasing the lines of code (allowing for the fact that I've added three lines of comments)!