diff --git a/core/java/android/app/SharedPreferencesImpl.java b/core/java/android/app/SharedPreferencesImpl.java index 1ebf56550e03d..6d3cb0ee24135 100644 --- a/core/java/android/app/SharedPreferencesImpl.java +++ b/core/java/android/app/SharedPreferencesImpl.java @@ -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); }