8000 Reuse cached erased TypeMirrors for Collection/Map/Stream checks by NabilJarrai · Pull Request #1 · spring-mapstruct/mapstruct · GitHub
[go: up one dir, main page]

Skip to content

Reuse cached erased TypeMirrors for Collection/Map/Stream checks#1

Open
NabilJarrai wants to merge 1 commit intospring-mapstruct:mainfrom
NabilJarrai:feature/cache-erased-type-mirrors
Open

Reuse cached erased TypeMirrors for Collection/Map/Stream checks#1
NabilJarrai wants to merge 1 commit intospring-mapstruct:mainfrom
NabilJarrai:feature/cache-erased-type-mirrors

Conversation

@NabilJarrai
Copy link

Summary

  • isCollection(), isMap(), and isStream() in Type.java were redundantly resolving TypeElements and erasing them on every call inside getAlternativeTargetAccessors(), scaling linearly with the number of properties
  • TypeFactory already caches these exact erased TypeMirror values at construction time, so I exposed them via package-private getters and rewired Type to use them directly
  • Removed the now-unused isSubType(TypeMirror, Class<?>) helper and the stale JavaStreamConstants import

Test plan

  • Verified mvn compile passes on the processor module
  • Confirmed test results are identical before and after the change

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.
Copilot AI review requested due to automatic review settings March 9, 2026 01:20
Copy link
Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for Collection, Map, and Stream from TypeFactory via package-private getters.
  • Rewire Type#isCollection(), Type#isMap(), and Type#isStream() to use the cached TypeMirrors 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0