Merge "Sort keys from top-left to bottom-right order"
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 88174ba..38359fc 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -460,6 +460,7 @@
                 dictFile.length(), mIsUpdatable);
     }
 
+    // Flush to dict file if the dictionary has been updated.
     public void flush() {
         if (!isValidDictionary()) return;
         if (mHasUpdated) {
@@ -468,6 +469,14 @@
         }
     }
 
+    // Run GC and flush to dict file if the dictionary has been updated.
+    public void flushWithGCIfHasUpdated() {
+        if (mHasUpdated) {
+            flushWithGC();
+        }
+    }
+
+    // Run GC and flush to dict file.
     public void flushWithGC() {
         if (!isValidDictionary()) return;
         flushWithGCNative(mNativeDict, mDictFilePath);
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 64e9d2b..a6a7354 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -515,7 +515,8 @@
         createBinaryDictionaryLocked();
         openBinaryDictionaryLocked();
         loadInitialContentsLocked();
-        mBinaryDictionary.flushWithGC();
+        // Run GC and flush to file when initial contents have been loaded.
+        mBinaryDictionary.flushWithGCIfHasUpdated();
     }
 
     private void flushDictionaryLocked() {