Skip to content

Commit 7355903

Browse files
committed
Fixed perf degradation on reindent (closes #96)
1 parent 45bec13 commit 7355903

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cs_indent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def search_path(node, pos):
1414
break
1515
return res
1616

17-
def indent(view, point):
17+
def indent(view, point, parsed = None):
1818
"""
1919
Given point, returns (tag, row, indent) for that line, where indent
2020
is a correct indent based on the last unclosed paren before point.
@@ -24,7 +24,7 @@ def indent(view, point):
2424
2525
Row is row number of the token for which this indent is based on (row of open paren)
2626
"""
27-
parsed = cs_parser.parse(view.substr(sublime.Region(0, point)) + ' ')
27+
parsed = parsed or cs_parser.parse(view.substr(sublime.Region(0, point)) + ' ')
2828
if path := search_path(parsed, point):
2929
node = None
3030
first_form = None
@@ -82,6 +82,7 @@ def indent_lines(view, selections, edit):
8282
Given set of sorted ranges (`selections`), indents all lines touched by those selections
8383
"""
8484
# Calculate all replacements first
85+
parsed = cs_parser.parse(view.substr(sublime.Region(0, view.size())) + ' ')
8586
replacements = {} # row -> (begin, delta_i)
8687
for sel in selections:
8788
for line in view.lines(sel):
@@ -91,7 +92,7 @@ def indent_lines(view, selections, edit):
9192
if end == line.end():
9293
continue
9394
row, _ = view.rowcol(begin)
94-
type, base_row, i = indent(view, begin)
95+
type, base_row, i = indent(view, begin, parsed)
9596
# do not re-indent multiline strings
9697
if type == 'string':
9798
continue

0 commit comments

Comments
 (0)