am 6f5d2ded: am a2174bad: am 5fa96540: Merge "Clear traverse sessions when closing."

* commit '6f5d2ded3fe105b40bdf4f419fe7426421548aff':
  Clear traverse sessions when closing.
main
Keisuke Kuroyanagi 2013-10-03 13:20:47 -07:00 committed by Android Git Automerger
commit 12f9d9cc85
1 changed files with 15 additions and 11 deletions

View File

@ -35,6 +35,7 @@ import java.util.Locale;
/** /**
* Implements a static, compacted, binary dictionary of standard words. * Implements a static, compacted, binary dictionary of standard words.
*/ */
// TODO: All methods which should be locked need to have a suffix "Locked".
public final class BinaryDictionary extends Dictionary { public final class BinaryDictionary extends Dictionary {
private static final String TAG = BinaryDictionary.class.getSimpleName(); private static final String TAG = BinaryDictionary.class.getSimpleName();
@ -283,22 +284,23 @@ public final class BinaryDictionary extends Dictionary {
removeBigramWordsNative(mNativeDict, codePoints0, codePoints1); removeBigramWordsNative(mNativeDict, codePoints0, codePoints1);
} }
public void flush() { private void reopen() {
if (!isValidDictionary()) return; close();
flushNative(mNativeDict, mDictFilePath);
closeNative(mNativeDict);
final File dictFile = new File(mDictFilePath); final File dictFile = new File(mDictFilePath);
mNativeDict = openNative(dictFile.getAbsolutePath(), 0 /* startOffset */, mNativeDict = openNative(dictFile.getAbsolutePath(), 0 /* startOffset */,
dictFile.length(), true /* isUpdatable */); dictFile.length(), true /* isUpdatable */);
} }
public void flush() {
if (!isValidDictionary()) return;
flushNative(mNativeDict, mDictFilePath);
reopen();
}
public void flushWithGC() { public void flushWithGC() {
if (!isValidDictionary()) return; if (!isValidDictionary()) return;
flushWithGCNative(mNativeDict, mDictFilePath); flushWithGCNative(mNativeDict, mDictFilePath);
closeNative(mNativeDict); reopen();
final File dictFile = new File(mDictFilePath);
mNativeDict = openNative(dictFile.getAbsolutePath(), 0 /* startOffset */,
dictFile.length(), true /* isUpdatable */);
} }
public boolean needsToRunGC() { public boolean needsToRunGC() {
@ -338,21 +340,23 @@ public final class BinaryDictionary extends Dictionary {
traverseSession.close(); traverseSession.close();
} }
} }
mDicTraverseSessions.clear();
} }
closeInternal(); closeInternalLocked();
} }
private synchronized void closeInternal() { private synchronized void closeInternalLocked() {
if (mNativeDict != 0) { if (mNativeDict != 0) {
closeNative(mNativeDict); closeNative(mNativeDict);
mNativeDict = 0; mNativeDict = 0;
} }
} }
// TODO: Manage BinaryDictionary instances without using WeakReference or something.
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
closeInternal(); closeInternalLocked();
} finally { } finally {
super.finalize(); super.finalize();
} }