Skip to content

Commit

Permalink
Improve performance by merging View.substr calls (#623)
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
  • Loading branch information
jfcherng committed Nov 8, 2023
1 parent 6bab50c commit bd058d7
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions bh_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ def save_content_regions(self, left, right, bracket, lines):
count = 0
# Calculate column index of where text starts for line
# containing opening bracket
for x in range(start_pt, start_pt + end_pt):
char = self.view.substr(x)
for char in self.view.substr(sublime.Region(start_pt, start_pt + end_pt)):
if char == "\t":
# Track all tabs
tabs += 1
Expand Down Expand Up @@ -380,8 +379,7 @@ def save_content_regions(self, left, right, bracket, lines):
# Loop through all lines after the first.
# Calculate the true column position where the bar should
# be drawn. Calculation should account for tabs.
for y in range(start_pt, start_pt + end_pt):
char = self.view.substr(y)
for char in self.view.substr(sublime.Region(start_pt, start_pt + end_pt)):
if char == '\x00':
# Extended past the file's end
actual_pt += 1
Expand Down Expand Up @@ -411,12 +409,10 @@ def save_content_regions(self, left, right, bracket, lines):
if self.view.rowcol(actual_pt)[0] == x and actual_pt not in bracket_locations:
if x == last_line:
# Draw bar on last line if text comes before bracket
include = False
for y in range(actual_pt, right.begin):
if self.view.substr(y) not in whitespace:
include = True
break
if include:
if any(
char not in whitespace
for char in self.view.substr(sublime.Region(actual_pt, right.begin))
):
bracket.content_selections.append(sublime.Region(actual_pt))
else:
# Content line; draw bar
Expand All @@ -428,12 +424,10 @@ def save_content_regions(self, left, right, bracket, lines):
if pt not in bracket_locations:
if x == last_line:
# Draw bar on last line if text comes before bracket
include = False
for y in range(pt, right.begin):
if self.view.substr(y) not in whitespace:
include = True
break
if include:
if any(
char not in whitespace
for char in self.view.substr(sublime.Region(pt, right.begin))
):
bracket.content_selections.append(sublime.Region(pt))
else:
# Content line; draw bar
Expand Down

0 comments on commit bd058d7

Please sign in to comment.