Skip to content

Fix minor warnings #1863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2019
Merged

Fix minor warnings #1863

merged 1 commit into from
Aug 18, 2019

Conversation

Captain1653
Copy link
Contributor

@Captain1653 Captain1653 commented Aug 12, 2019

Fix minor warnings:
remove unnecessary generic type for collections,
replace Charset.forName on StandartCharsets

@Captain1653 Captain1653 changed the title Remove duplicate code in methods getThrownTypes() in package assignment, fix minor warnings Refactor duplicate code in methods getThrownTypes() in package assignment, fix minor warnings Aug 12, 2019
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.

Thanks for the PR @Captain1653.

I have some comments about it though.

Regarding the changes for changing the for loops with Collectors.toList(). There is one small performance problem about it. The performance is linked with the size of the list.

For example

List<String> strings = createStrings();
List<Integer> result = new ArrayList<>( strings.size() );

for (String string: strings) {
    result.add( Integer.parse( string ) );
}

vs

List<String> strings = createStrings();
List<Integer> result = strings.stream().map( Integer::parse ).collect( Collectors.toList() );

Both are semantically the same. However, in the first approach the result list is created with the expected size and in the second one it isn't. This means that when creating the result there will be a lot of expansions of the underlying array in ArrayList. In theory this could be done with Collectors.tolCollection( () -> new ArrayList( strings.size() ) ). However, I am not sure whether that is better or not.

It is similar for doing the remove in the getThrownTypes()

@Captain1653
Copy link
Contributor Author

Captain1653 commented Aug 18, 2019

@filiphr
I think you are right about size of ArrayList and expansions. I can replace it with custom supplier or revert this changes. What is better?

P.S. From javadoc ArrayList java 8:

An empty ArrayList with elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA will be expanded to DEFAULT_CAPACITY when the first element is added.

@filiphr
Copy link
Member

filiphr commented Aug 18, 2019

I think that for the time being it is better to leave the for loops as is.

Not following what you mean about the javadoc.

remove unnecessary generic type for collections,
replace Charset.forName on StandartCharset
@Captain1653 Captain1653 changed the title Refactor duplicate code in methods getThrownTypes() in package assignment, fix minor warnings Fix minor warnings Aug 18, 2019
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.

Thanks for applying the changes @Captain1653. Will merge it once the build is done

@filiphr filiphr merged commit 59a5182 into mapstruct:master Aug 18, 2019
@Captain1653 Captain1653 deleted the remove_duplicate_assignment branch August 18, 2019 14:29
@filiphr filiphr added this to the 1.4.0 milestone May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants