don't buffer commonmark output unless necessary. #684
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.
The status quo is that
cmwill buffer all output inself.output, which gets written out all-at-once to the providedfmt::Write.If we're not wrapping (
options.render.width > 0), and we're not using the experimental escape minimizer (GH-523), we don't need to buffer output at all.If we're wrapping, we need to buffer at most until a line break or wrapping event occurs.
If we're using the experimental escape minimizer, we still have to buffer everything.
It was annoying to move from doing things this way (made easy by the reference C implementation) because we need to know some properties of the last few bytes written out; whether up to the last two bytes were linefeeds, and whether the last byte was an ASCII digit. We keep a window of the last two bytes written out to furnish this.