Improvement: Precalculate the cell content #98
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cause: In
print_row_in_cell
, the text is wrapped (byword_wrap
) and split (bysplit_lines
) too early before checking the padding settings.word_wrap
andsplit_lines
before callingprint_row_in_cell
to improve the printing complixityDetail: In
print_row_in_cell
,word_wrap
andsplit_lines
will be called once for each cell each line they have. When the content of the cell and the number of lines are both large, the computation time will grow massively.In this PR, the computation is moved before the actual printing procedure, so those functions won't get called multiple times for each cell, and also avoid the bug mentioned by using the correct line height in
print_row_in_cell
.Further todo: the code in
Row::get_cell_height
is also similar to these, maybe we should reuse the code.The example of the bug (the upper one is before, and the lower one is after):

Reproduce code:
Additional check for not breaking another sample:

I did a manual check for all the samples and hope there's no accident.