Skip to content

Optimize map operations by removing redundant containsKey checks#380

Open
OverwriteMC wants to merge 3 commits intoDecentSoftware-eu:mainfrom
OverwriteMC:main
Open

Optimize map operations by removing redundant containsKey checks#380
OverwriteMC wants to merge 3 commits intoDecentSoftware-eu:mainfrom
OverwriteMC:main

Conversation

@OverwriteMC
Copy link
Copy Markdown

Motivation: We don't need to do the same action multiple times. containsKey and get generally perform identical checks, so by combining the get method with a null check, we avoid unnecessary CPU and RAM usage with the containsKey method

to avoid double map operations
To optimize this check
get method returns the object we need, and if it's not in the map, it returns null. containsKey, on the other hand, performs the same operations as get but doesn't return anything
сhecking for null is faster than performing double operations, so it's efficient to avoid calling containsKey
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