Skip to content

Add Maps.newLinkedHashMapWithExpectedSize #84054

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 4 commits into from
Feb 21, 2022

Conversation

arteam
Copy link
Contributor

@arteam arteam commented Feb 16, 2022

No description provided.

@arteam arteam force-pushed the pre-size-linkedhashmap branch from e4286b3 to 5705b66 Compare February 17, 2022 08:15
@arteam
Copy link
Contributor Author

arteam commented Feb 17, 2022

@elasticmachine update branch

@arteam arteam marked this pull request as ready for review February 17, 2022 10:55
@arteam arteam added the :Core/Infra/Core Core issues without another label label Feb 17, 2022
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Feb 17, 2022
@arteam arteam removed WIP Team:Core/Infra Meta label for core/infra team labels Feb 17, 2022
* @param <V> the value type
* @return a new pre-sized {@link LinkedHashMap}
*/
public static <K, V> Map<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) {
Copy link
Contributor

@idegtiarenko idegtiarenko Feb 17, 2022

Choose a reason for hiding this comment

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

I would recommend to keep the return type as LinkedHashMap. No need to hide implementation as it is already in the name. This will also avoid the type casts in some use cases

keys.put("foo.date_histogram", 123L);

char[] charArray = new char[IndexWriter.MAX_TERM_LENGTH];
Arrays.fill(charArray, 'a');
keys.put("bar.terms", new String(charArray));
keys.put("abc.histogram", 1.9);
keys = shuffleMap(keys, Collections.emptySet());
keys = shuffleMap((LinkedHashMap<String, Object>) keys, Collections.emptySet());
Copy link
Contributor

Choose a reason for hiding this comment

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

This and above type cast could be avoided. See my other comment

@arteam
Copy link
Contributor Author

arteam commented Feb 21, 2022

@elasticmachine run elasticsearch-ci/part-1

@arteam arteam merged commit 36e0298 into elastic:master Feb 21, 2022
@arteam arteam deleted the pre-size-linkedhashmap branch February 21, 2022 10:18
@arteam
Copy link
Contributor Author

arteam commented Feb 21, 2022

Thanks Ievgen!

probakowski pushed a commit to probakowski/elasticsearch that referenced this pull request Feb 23, 2022
* Add Maps.newLinkedHashMapWithExpectedSize
* Return LinkedHashMap
* Don't cast LinkedHashMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants