Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizes View::screen_coords_at_pos by not computing char_to_line two times #4896

Closed

Conversation

zummenix
Copy link
Contributor

This solves a todo in View::screen_coords_at_pos method to not compute char_to_line two times.

I've introduced a new function core::visual_col_position which additionally accepts a row index. Also I've made corresponding changes in core::position module to remove some code duplication.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Nov 27, 2022
Comment on lines +171 to +175
fn rope_graphemes(text: RopeSlice, pos: usize, row: usize) -> RopeGraphemes {
let row_start = text.line_to_char(row);
let pos = ensure_grapheme_boundary_prev(text, pos);
RopeGraphemes::new(text.slice(row_start..pos))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not so much code that it needs a helper function IMO, and it's a bit confusing that there are other calls to RopeGraphemes::new that don't use rope_graphemes in this module. This can be inlined into the two callsites

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Respectfully, I disagree. This function encapsulates an important concept that text should be sliced taking into account grapheme boundaries. Maybe the name for the function and the place should be different but otherwise...

I don't know why in other places that's not the case, haven't looked deep.

Let's close this PR because neither I nor you don't have time to argue.

Comment on lines -77 to -78
let line = text.char_to_line(pos);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small stylistic nit but it's more common in the codebase to see line when translating a position to a line number (rather than row)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is just a language barrier but for me it was confusing because there is row in Position. In any case I'm fine with any name.

@pascalkuthe
Copy link
Member

Just a small heads: As Part of #5008 I will be replacing entire positioning code (including this function) to take virtual text, softwrapping and other kinds of decoration into account. Even if my specific PR doesn't get merged. Any implementation of these features will have to replace this code. A quick-fix could be nice but it's probably not worth investing a lot of time into optimizing a functiion that will be replaced in the future anyway

@zummenix
Copy link
Contributor Author

Good to know. Thanks! Closing

@zummenix zummenix closed this Dec 12, 2022
@zummenix zummenix deleted the optimize-screen_coords_at_pos branch December 12, 2022 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants