Skip to content
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

Fixed jdk8 Map computeIfAbsent performance bug #4338

Merged
merged 3 commits into from
Feb 9, 2023

Conversation

caojiajun
Copy link
Contributor

@caojiajun caojiajun commented Jan 31, 2023

Fixed jdk8 Map computeIfAbsent performance bug
see https://bugs.openjdk.org/browse/JDK-8161372

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@caojiajun
Copy link
Contributor Author

caojiajun commented Jan 31, 2023

add this utils method in MapUtils, and replace the computeIfAbsent direct invoke in project

    /**
     * jdk8 performance bug, see: https://bugs.openjdk.java.net/browse/JDK-8161372
     *
     * @param map source map
     * @param key key
     * @param mappingFunction mappingFunction
     * @param <K> k
     * @param <V> v
     * @return v
     */
    public static <K, V> V computeIfAbsent(Map<K, V> map, K key, Function<? super K, ? extends V> mappingFunction) {
        V v = map.get(key);
        if (v != null) return v;
        return map.computeIfAbsent(key, mappingFunction);
    }

@caojiajun
Copy link
Contributor Author

@midnight2104 pls help me review this pr

@yu199195 yu199195 added this to the 2.6.0 milestone Feb 8, 2023
@yu199195 yu199195 merged commit 0a136fa into apache:master Feb 9, 2023
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.

None yet

3 participants