Speed up cursor column calculation in the status bar for long lines - #753
Open
KAMI911 wants to merge 1 commit into
Open
Speed up cursor column calculation in the status bar for long lines#753KAMI911 wants to merge 1 commit into
KAMI911 wants to merge 1 commit into
Conversation
The status bar position indicator computed the column number by stepping through a GtkTextIter one character at a time from the start of the current line to the cursor, calling gtk_text_iter_get_char and gtk_text_iter_forward_char in a loop. This function runs on essentially every cursor movement, including while typing, so on a very long line, such as a minified script or a large single-line JSON file, it added a noticeable delay on each keystroke because the cost scaled with the cursor's column position. The loop now fetches the text between the start of the line and the cursor with a single gtk_text_iter_get_slice call and walks the resulting plain UTF-8 string instead, which avoids the repeated iterator validation and buffer lookups of the old approach while producing the exact same column number, including the same tab-expansion handling.
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.
The status bar position indicator computed the column number by stepping through a GtkTextIter one character at a time from the start of the current line to the cursor, calling gtk_text_iter_get_char and gtk_text_iter_forward_char in a loop. This function runs on essentially every cursor movement, including while typing, so on a very long line, such as a minified script or a large single-line JSON file, it added a noticeable delay on each keystroke because the cost scaled with the cursor's column position. The loop now fetches the text between the start of the line and the cursor with a single gtk_text_iter_get_slice call and walks the resulting plain UTF-8 string instead, which avoids the repeated iterator validation and buffer lookups of the old approach while producing the exact same column number, including the same tab-expansion handling.