diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d99a5d..b82884a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Setting `total=None` on progress is now possible, and will display pulsing animation +- Micro-optimization for Segment.divide ## [12.2.0] - 2022-04-05 diff --git a/rich/segment.py b/rich/segment.py index 1890cb61..d825cfca 100644 --- a/rich/segment.py +++ b/rich/segment.py @@ -611,9 +611,14 @@ class Segment(NamedTuple): yield [] pos = 0 + _cell_len = cell_len for segment in segments: - while segment.text: - end_pos = pos + segment.cell_length + text, _style, control = segment + while text: + if control: + end_pos = pos + else: + end_pos = pos + _cell_len(text) if end_pos < cut: add_segment(segment) pos = end_pos @@ -628,6 +633,7 @@ class Segment(NamedTuple): break else: before, segment = segment.split_cells(cut - pos) + text, _style, control = segment add_segment(before) yield split_segments[:] del split_segments[:]