Reuse cached erased TypeMirrors for Collection/Map/Stream checks#1
Open
NabilJarrai wants to merge 1 commit intospring-mapstruct:mainfrom
Open
Reuse cached erased TypeMirrors for Collection/Map/Stream checks#1NabilJarrai wants to merge 1 commit intospring-mapstruct:mainfrom
NabilJarrai wants to merge 1 commit intospring-mapstruct:mainfrom
Conversation
The private isCollection(), isMap(), and isStream() methods in Type were redundantly resolving TypeElements and erasing them on every call inside getAlternativeTargetAccessors(). TypeFactory already caches these exact erased TypeMirrors at construction time, so I exposed them via package-private getters and rewired Type to use them directly. Removed the now-unused isSubType helper method.
There was a problem hiding this comment.
Pull request overview
This PR reduces repeated type resolution work in the processor by reusing TypeFactory’s cached erased TypeMirrors when checking whether a candidate type is a Collection, Map, or Stream, avoiding per-call TypeElement resolution/erasure inside Type#getAlternativeTargetAccessors().
Changes:
- Expose cached erased
TypeMirrors forCollection,Map, andStreamfromTypeFactoryvia package-private getters. - Rewire
Type#isCollection(),Type#isMap(), andType#isStream()to use the cachedTypeMirrors and remove the redundant helper / import cleanup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java | Adds package-private getters for cached erased collectionType, mapType, and streamType. |
| processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java | Switches subtype checks to use TypeFactory’s cached type mirrors; removes now-unused helper and stale import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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.
Summary
isCollection(),isMap(), andisStream()inType.javawere redundantly resolvingTypeElements and erasing them on every call insidegetAlternativeTargetAccessors(), scaling linearly with the number of propertiesTypeFactoryalready caches these exact erasedTypeMirrorvalues at construction time, so I exposed them via package-private getters and rewiredTypeto use them directlyisSubType(TypeMirror, Class<?>)helper and the staleJavaStreamConstantsimportTest plan
mvn compilepasses on the processor module