Avoid repeated copying in clean_tokens
.
#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.
clean_tokens
takes a vector of tokens and removes some. The decisionof which tokens to remove is somewhat complicated, so it can't use
retain
orfilter
, but instead does everyting itself. This includescalling
remove
on every individual removed token. Unfortunately, thisresults in quadratic-ish behaviour when the number of tokens removed is
large, due to all the shuffling down of tokens after each removed token.
The closer the removed tokens are to the start of the vector, the worse
it is.
This commit switches to a two pass approach. The first pass records
which tokens should be removed, using an auxiliary vector of bools. The
second pass does the removal, using
Vec::retain
. When runningrustdoc
(which usesminifier
) onhelloworld
, this reducesmemcpy
traffic from this:
to this: