{{ message }}
Repository navigation
Avoid quadratic backtracking in vim modeline detection - #3410
Open
Support-itecz wants to merge 1 commit into
Open
Support-itecz wants to merge 1 commit into
Support-itecz wants to merge 1 commit into
Conversation
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.

get_filetype_from_line runs modeline_re.search() on the first and last lines of the buffer, and because the pattern is a modeline start followed by .* and an ft=/syn= assignment, a line with many starts and no assignment restarts the scan at every start, which is quadratic in the line length. guess_lexer() calls this before anything else, so guessing the language of a single 96 KB line of 'vi:' takes about 51 s (48 KB: 10 s); with this change it takes 5 ms, and 1 MB takes 50 ms. The .* can skip over any later start, so only the leftmost one can decide the result: find it with the prefix alone and run the existing pattern once with match() there, which returns the same filetype as before (checked against the old regex on 300k random lines).