This repository was archived by the owner on Nov 8, 2023. It is now read-only.
SharedPreferencesImpl.EditorImpl: Remove redundant map lookups in commitToMemory#585
Open
kunjan-a wants to merge 1 commit intoaosp-mirror:masterfrom
Open
SharedPreferencesImpl.EditorImpl: Remove redundant map lookups in commitToMemory#585kunjan-a wants to merge 1 commit intoaosp-mirror:masterfrom
commitToMemory#585kunjan-a wants to merge 1 commit intoaosp-mirror:masterfrom
Conversation
1. Instead of `HashMap.contains` check before `HashMap.remove`, directly perform `HashMap.remove`.
- When _key_ is not present there is no impact as exactly same code gets executed inside implementation of `HashMap.contains` and `HashMap.remove` for this case.
- When _key_ is present we save one wasteful hash lookup that would have happened due to `HashMap.contains`.
1. Instead of `HashMap.contains` check before `HashMap.get`, directly perform `HashMap.get`.
- When _key_ is not present there is no impact as exactly same `getNode` method gets invoked in both `HashMap.contains` and `HashMap.remove` implementations.
- When _key_ is present we same one wasteful hash lookup that would have happened due to `HashMap.contains`.
- Also we save on a null check by reversing the _equals_ check as we know new value to be added to map is not _null_.
|
Hello,我已收到邮件,待我仔细阅读后再回复。
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Instead of
HashMap.containscheck beforeHashMap.remove, directly performHashMap.remove.HashMap.containsandHashMap.removefor this case.HashMap.contains.Instead of
HashMap.containscheck beforeHashMap.get, directly performHashMap.get.getNodemethod gets invoked in bothHashMap.containsandHashMap.removeimplementations.HashMap.contains.