Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f99f81b authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Svetoslav Ganov
Browse files

Do not write if apply() did not change the file.

Bug: 33385963
Test: SharedPreferences CTS tests
Change-Id: I39955f8fbcdaa54faa539a3c503e12cb00808136
parent d15c4f1d
Loading
Loading
Loading
Loading
+10 −10
Original line number Original line Diff line number Diff line
@@ -592,20 +592,20 @@ final class SharedPreferencesImpl implements SharedPreferences {
        if (mFile.exists()) {
        if (mFile.exists()) {
            boolean needsWrite = false;
            boolean needsWrite = false;


            if (isFromSyncCommit) {
            // Only need to write if the disk state is older than this commit
            // Only need to write if the disk state is older than this commit
            if (mDiskStateGeneration < mcr.memoryStateGeneration) {
            if (mDiskStateGeneration < mcr.memoryStateGeneration) {
                if (isFromSyncCommit) {
                    needsWrite = true;
                    needsWrite = true;
                }
                } else {
                } else {
                    synchronized (this) {
                    synchronized (this) {
                    // No need to persist intermediate states. Just wait for the latest state to be
                        // No need to persist intermediate states. Just wait for the latest state to
                    // persisted.
                        // be persisted.
                        if (mCurrentMemoryStateGeneration == mcr.memoryStateGeneration) {
                        if (mCurrentMemoryStateGeneration == mcr.memoryStateGeneration) {
                            needsWrite = true;
                            needsWrite = true;
                        }
                        }
                    }
                    }
                }
                }
            }


            if (!needsWrite) {
            if (!needsWrite) {
                if (DEBUG) {
                if (DEBUG) {