Add BinaryDictionary.flushWithGCIfHasUpdated().

Bug: 14166482
Bug: 14161647
Change-Id: I98b0a8b86897b1486491a3aea91729bc9e4cc03c
main
Keisuke Kuroyanagi 2014-04-21 15:21:55 -07:00
parent 7b43d987fa
commit c6704dbe51
2 changed files with 11 additions and 1 deletions

View File

@ -460,6 +460,7 @@ public final class BinaryDictionary extends Dictionary {
dictFile.length(), mIsUpdatable); dictFile.length(), mIsUpdatable);
} }
// Flush to dict file if the dictionary has been updated.
public void flush() { public void flush() {
if (!isValidDictionary()) return; if (!isValidDictionary()) return;
if (mHasUpdated) { if (mHasUpdated) {
@ -468,6 +469,14 @@ public final class BinaryDictionary extends Dictionary {
} }
} }
// 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() { public void flushWithGC() {
if (!isValidDictionary()) return; if (!isValidDictionary()) return;
flushWithGCNative(mNativeDict, mDictFilePath); flushWithGCNative(mNativeDict, mDictFilePath);

View File

@ -515,7 +515,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
createBinaryDictionaryLocked(); createBinaryDictionaryLocked();
openBinaryDictionaryLocked(); openBinaryDictionaryLocked();
loadInitialContentsLocked(); loadInitialContentsLocked();
mBinaryDictionary.flushWithGC(); // Run GC and flush to file when initial contents have been loaded.
mBinaryDictionary.flushWithGCIfHasUpdated();
} }
private void flushDictionaryLocked() { private void flushDictionaryLocked() {