[3.x] Fix TextEdit color_region_cache
bug
#74777
Merged
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.
Due to a single error,
_is_line_in_region
was previously iterating over the color highlighting for the entire document repeatedly for each line in the script.This is now fixed, which should make the editor much faster with large scripts.
Explanation
The loop is meant to find the first line that is in the cache, but due to the error, it repeatedly checks whether the same line is in the cache, so it never breaks, and always reaches the beginning, so
previous_line
is incorrect throughout the rest of the routine.Partially fixes #74733
Notes
This bug was really bad for performance - debug logging revealed that for each line of script the syntax highlighter evaluated every previous line, each time, so the performance drop was with the square of the number of lines, something like that.
i.e.
CodeHighlighter
there is correct in the same place.