Add BinaryDictionary.flushWithGCIfHasUpdated().
Bug: 14166482
Bug: 14161647
Change-Id: I98b0a8b86897b1486491a3aea91729bc9e4cc03c
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 5e36d97..621eb2d 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() {