Repository navigation
Avoid quadratic clearing of JsonArray sublists - #3157
Open
wozhenbang2004 wants to merge 2 commits into
Open
wozhenbang2004 wants to merge 2 commits into
wozhenbang2004 wants to merge 2 commits into
Conversation
Delegate range removal to the backing ArrayList so clearing a sublist does not repeatedly shift the remaining elements.
…ublist views Cover middle, nested, and empty ranges and verify that changes remain visible through the backing JsonArray and list views.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
Clearing a range through
JsonArray.asList().subList(from, to).clear()currently performs quadratic work for large ranges.Description
NonNullElementWrapperListinheritsAbstractList.removeRange, which removes each element separately. Each indexed removal shifts the remaining elements in its backingArrayList. OverrideremoveRangeto delegate to the backing list's sublist clear, which removes the range in one operation. This complements #3115 for a separate bulk-removal path.Add tests to the existing
JsonArrayAsListTestfor middle, nested, and empty ranges, continued use of a cleared view, and consistency with the backingJsonArray. No public API is added.Validation: compiled the complete wrapper source in memory with JDK 17, including with
--release 8, and ran behavior and operation-count probes. Clearing 50,000 elements from a 100,000-element list invokedremove(int)50,000 times before this change and zero times afterward. Middle/nested/empty ranges, further insertion through the cleared view, and null rejection passed. The added unit tests cover view behavior; the operation-count probe checks the performance regression. The full Maven/JUnit suite has not been run locally; the existing PR workflows will provide that validation.Checklist
This is automatically checked by
mvn verify, but can also be checked on its own usingmvn spotless:check.Style violations can be fixed using
mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.null@since $next-version$(
$next-version$is a special placeholder which is automatically replaced during release)TestCase)mvn clean verify javadoc:jarpasses without errors