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

optimize lsp_pos_to_pos #1423

Merged
merged 1 commit into from
Jan 3, 2022
Merged

optimize lsp_pos_to_pos #1423

merged 1 commit into from
Jan 3, 2022

Conversation

kirawi
Copy link
Member

@kirawi kirawi commented Jan 2, 2022

Seems to work.

@kirawi kirawi force-pushed the opt branch 2 times, most recently from 31134bf to 4615fde Compare January 2, 2022 20:33
@kirawi kirawi changed the title optimize pos_to_pos lsp functions optimize lsp_pos_to_pos Jan 2, 2022
@@ -66,39 +66,26 @@ pub mod util {
pos: lsp::Position,
offset_encoding: OffsetEncoding,
) -> Option<usize> {
let max_line = doc.lines().count().saturating_sub(1);
Copy link
Member

Choose a reason for hiding this comment

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

Oh wow, that was missed in the original PR review.

let pos_line = pos.line as usize;
let pos_line = if pos_line > max_line {
if pos_line > doc.len_lines() - 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Should still use saturating_sub if you have 0 lines (no line endings)

Copy link
Member Author

@kirawi kirawi Jan 3, 2022

Choose a reason for hiding this comment

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

I noticed that it would return 1 even on an empty string "" in the tests:

test_case!("", (1, 0) => None);

Copy link
Member

Choose a reason for hiding this comment

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

Looks good then 👍🏻

@archseer archseer merged commit ea095ca into helix-editor:master Jan 3, 2022
@kirawi kirawi deleted the opt branch January 3, 2022 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants