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

Avoid unnecessary Map.containsKey calls. #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

turbanoff
Copy link
Contributor

Map.containsKey calls are often unnecessary.
Depends on the code, we can:

  1. call get() and then compare result with null. Applicable if we know that Map don't contain null value
  2. use putIfAbsent()/computeIfAbsent() if containsKey() was used before put
  3. use getOrDefault() if we have "fallback" value

I believe it simplifies code and makes it a bit faster.

Map.containsKey calls are often unnecessary.
Depends on the code, we can:
 1. call get() and then compare result with null. Applicable if we know that Map don't contain null value
 2. use putIfAbsent()/computeIfAbsent() if containsKey() was used before put
 3. use getOrDefault() if we have "fallback" value
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.

1 participant