Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Dec 14, 2021
1 parent c2c506f commit c3e0f7d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions rich/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def divide(self, offsets: Iterable[int]) -> Lines:
if not self._spans:
return new_lines

_lines = [line._spans.append for line in new_lines._lines]
_line_appends = [line._spans.append for line in new_lines._lines]
line_count = len(line_ranges)
_Span = Span

Expand Down Expand Up @@ -1091,14 +1091,12 @@ def divide(self, offsets: Iterable[int]) -> Lines:
break
end_line_no = (lower_bound + upper_bound) // 2

for line, (line_start, line_end) in zip(
_lines[start_line_no : end_line_no + 1],
line_ranges[start_line_no : end_line_no + 1],
):
for line_no in range(start_line_no, end_line_no + 1):
line_start, line_end = line_ranges[line_no]
new_start = max(0, span_start - line_start)
new_end = min(span_end - line_start, line_end - line_start)
if new_end > new_start:
line(_Span(new_start, new_end, style))
_line_appends[line_no](_Span(new_start, new_end, style))

return new_lines

Expand Down

0 comments on commit c3e0f7d

Please sign in to comment.