Skip to content

Improve builder value fill#20

Open
hduelme wants to merge 7 commits intomapstruct:mainfrom
hduelme:improve-builder-value-fill
Open

Improve builder value fill#20
hduelme wants to merge 7 commits intomapstruct:mainfrom
hduelme:improve-builder-value-fill

Conversation

@hduelme
Copy link
Contributor

@hduelme hduelme commented Feb 13, 2026

I changed the generated code to use java switch string matching, if there are more than 3 strings to check. For this I extracted the builder fill code into fillBuilder macro.
I although changed the loop iteration to use entrySet.

@hduelme
Copy link
Contributor Author

hduelme commented Feb 13, 2026

I tested the this improvement with mapstruct and found a small improvement (about 100ms for mapstruct-processor in MapperGem), manly due to the reduction in String comparison.

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

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

This reads way better @hduelme. Thanks a lot for the improvements. I've left some comments.

Apart of the comments, I see that we have a lot of values.get( methodName ) and defaultMethod.getValue(). Won't it be a bit better if we assign them at the beginning of the if / switch?

e.g.

String methodName = defaultMethod.getKey();
switch ( methodName ) {
    case "myClassWithDefault":
        builder.setMyclasswithdefault( GemValue.create( values.get( methodName ), defaultMethod.getValue(), TypeMirror.class ) );
        break;

Would become

String methodName = defaultMethod.getKey();
AnnotationValue defaultValue = defaultMethod.getValue();
AnnotationValue value = values.get( methodName );
switch ( methodName ) {
    case "myClassWithDefault":
        builder.setMyclasswithdefault( GemValue.create( value, defaultValue, TypeMirror.class ) );
        break;

@filiphr
Copy link
Member

filiphr commented Feb 14, 2026

I tested the this improvement with mapstruct and found a small improvement (about 100ms for mapstruct-processor in MapperGem), manly due to the reduction in String comparison.

That's great

@hduelme
Copy link
Contributor Author

hduelme commented Feb 15, 2026

@filiphr I've addressed your comments. I agree that moving defaultValue and value in front of the switch/if statement improves readability. I've made that change.

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.

2 participants