Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

SharedPreferencesImpl.EditorImpl: Remove redundant map lookups in commitToMemory #585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions core/java/android/app/SharedPreferencesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,14 @@ private MemoryCommitResult commitToMemory() {
// setting a value to "null" for a given key is specified to be
// equivalent to calling remove on that key.
if (v == this || v == null) {
if (!mapToWriteToDisk.containsKey(k)) {
if (mapToWriteToDisk.remove(k) == null) {
//mapToWriteToDisk does not contain given key, k
continue;
}
mapToWriteToDisk.remove(k);
} else {
if (mapToWriteToDisk.containsKey(k)) {
Object existingValue = mapToWriteToDisk.get(k);
if (existingValue != null && existingValue.equals(v)) {
continue;
}
if (v.equals(mapToWriteToDisk.get(k))) {
//mapToWriteToDisk already contains the same key value pairing
continue;
}
mapToWriteToDisk.put(k, v);
}
Expand Down