Printing arguments: short circuiting some cases #6229
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.
So when investigating #4784, I've managed to verify the issue was in
printArgumentsList()
, more specifically the part where we check if it should hug the first of the last argument, and later, verified the issue was in theconditionalGroup
, and more specifically, the first possible group, with a combination ofifBreak()
andsoftline
.The previous code had the following meaning: if the group breaks, print all arguments broken down; else, just concat the arguments with the wrapping parenthesis (note that there are some cases where we print a new line but the group doesn't break!).
So the first thing I changed was: if none of the arguments break beforehand (this is before printing, so this means the argument "doc" already includes something that makes it break. It can break later when printing if it exceeds the print width), we can try a simple concat. If it fails, it will continue to the next cases in the conditional group. And only if one of the arguments break beforehand, we use the
ifBreak()
.. another change is instead of usingsoftline
for the ifBreak case, just print a hardline instead.These changes didn't break any existing tests and fix the performance degradation.
The execution time comes down to 0.58s.
Closes #4784