Some code organization changes in ShapeLine::layout
#170
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.
I was reading through this code (to get a better understanding of how alignment is applied and potential avenues for reusing layout work done for width measurement when performing the final layout) and noticed a few things that could be easily de-duplicated or adjusted to improve clarity (IMO).
ShapeLine::layout
weren't used until the second phase which is much farther down, so I moved them down to be at the start of that phase.push_line
bool
with checkinglayout_lines.is_empty()
which is effectively equivalent.visual_lines
were reset with each loop iteration, so I moved their definitions down into the loop.justification_expansion
instead of reusing thealignment_correction
variable (which just shifts the line in all other modes, but was used to hold how much each space should be expanded when justifying). This is more clear to the reader and avoids several later checks of whether the alignment isAlign::Justified
in spots wherealignment_correction
is used. (I may have gone overboard with the other changes but I think at least this one is pretty useful)process_range
closure as well as combine several cases of iterating over glyphs during this.mem::swap(&mut glyphs, &mut glyphs_swap);
(glyphs
is not used later and can just be directly moved out of)None of these changes should affect the behavior (If I didn't make any mistakes!).