Skip to content

Commit 04fa3e5

Browse files
fukanchikSergey Fukanchik
andauthored
Do not call str.splitlines() twice in the same function. (#628)
Co-authored-by: Sergey Fukanchik <[email protected]>
1 parent cc6d398 commit 04fa3e5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎pylsp/workspace.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ def apply_change(self, change):
460460
end_col=change_range["end"]["character"]
461461

462462
# Check for an edit occuring at the very end of the file
463-
ifstart_line==len(self.lines):
463+
lines=self.lines
464+
ifstart_line==len(lines):
464465
self._source=self.source+text
465466
return
466467

@@ -469,7 +470,7 @@ def apply_change(self, change):
469470
# Iterate over the existing document until we hit the edit range,
470471
# at which point we write the new text, then loop until we hit
471472
# the end of the range and continue writing.
472-
fori, lineinenumerate(self.lines):
473+
fori, lineinenumerate(lines):
473474
ifi<start_line:
474475
new.write(line)
475476
continue
@@ -493,10 +494,11 @@ def offset_at_position(self, position):
493494

494495
defword_at_position(self, position):
495496
"""Get the word under the cursor returning the start and end positions."""
496-
ifposition["line"] >=len(self.lines):
497+
lines=self.lines
498+
ifposition["line"] >=len(lines):
497499
return""
498500

499-
line=self.lines[position["line"]]
501+
line=lines[position["line"]]
500502
i=position["character"]
501503
# Split word in two
502504
start=line[:i]

0 commit comments

Comments
(0)