Skip to content

Commit cbce014

Browse files
Optimize char access in LSP edit lookup
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
1 parent 514e6c0 commit cbce014

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎tools/lsp/src/lib.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,11 @@ impl LanguageServer for Backend {
752752
while let Some(pos_in_line) = line[start_pos..].find(&word) {
753753
let actual_pos = start_pos + pos_in_line;
754754
let char_before = if actual_pos > 0 {
755-
line.chars().nth(actual_pos - 1)
755+
line[..actual_pos].chars().next_back()
756756
} else {
757757
None
758758
};
759-
let char_after = line.chars().nth(actual_pos + word_len);
759+
let char_after = line[actual_pos + word_len..].chars().next();
760760

761761
let is_boundary_before =
762762
char_before.map_or(true, |c| !c.is_alphanumeric() && c != '_');
@@ -803,11 +803,11 @@ impl LanguageServer for Backend {
803803
while let Some(pos_in_line) = line[start_pos..].find(&word) {
804804
let actual_pos = start_pos + pos_in_line;
805805
let char_before = if actual_pos > 0 {
806-
line.chars().nth(actual_pos - 1)
806+
line[..actual_pos].chars().next_back()
807807
} else {
808808
None
809809
};
810-
let char_after = line.chars().nth(actual_pos + word_len);
810+
let char_after = line[actual_pos + word_len..].chars().next();
811811

812812
let is_boundary_before =
813813
char_before.map_or(true, |c| !c.is_alphanumeric() && c != '_');

0 commit comments

Comments
 (0)