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.
In case the input is shorter than the wrapping width, we can return it immediately. This avoids findings words, breaking them, and finally reassembling them.
The speedup from the is on the order of 10-25 times, depending on the wrapping width. I tested with a wrapping width of 60 columns and there the time for
fill("")
is now around 15 nanoseconds. It was around 150 nanoseconds before:A similar 10x improvement is seen for
fill("abcde")
:As strings get longer and closer to the wrapping width, the improvements get larger. Before it took just shy of a microsecond to wrap a 50 character string on my machine:
Now it only takes 34 nanoseconds, a 27x improvement:
The time needed to wrap the input is nearly flat until you hit the wrapping width, as which time it grows linearly with the input length: