Avoid using ArrayList in MonotoneChain builders #467
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.
As discussed in #463, currently
MonotoneChain
construction uses a temporaryArrayList
to accumulate int index values. This causes unnecessary object allocation, and may be slower (although this is not certain).The use of
ArrayList
is avoided in two ways:MonotoneChainBuilder
can be refactored to avoid using a array of indexes completely, by constructingMonotoneChain
objects as they determinedMonotoneChainIndexer
the return of anint[]
is required, but it is changed to use a new utility classIntArrayList
. This class uses primitiveint
values, and so should have less memory pressure than anArrayList
ofInteger