Quit blocking getSuggestion during GC.
Bug: 10831272 Change-Id: I995c619dc18a9120a47f547d31045cb73a9353ecmain
parent
2c1faeda2c
commit
03cb8f751a
|
@ -269,18 +269,11 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
return getBigramProbabilityNative(mNativeDict, codePoints0, codePoints1);
|
return getBigramProbabilityNative(mNativeDict, codePoints0, codePoints1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runGCIfRequired() {
|
|
||||||
if (needsToRunGC(true /* mindsBlockByGC */)) {
|
|
||||||
flushWithGC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a unigram entry to binary dictionary in native code.
|
// Add a unigram entry to binary dictionary in native code.
|
||||||
public void addUnigramWord(final String word, final int probability) {
|
public void addUnigramWord(final String word, final int probability) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runGCIfRequired();
|
|
||||||
final int[] codePoints = StringUtils.toCodePointArray(word);
|
final int[] codePoints = StringUtils.toCodePointArray(word);
|
||||||
addUnigramWordNative(mNativeDict, codePoints, probability);
|
addUnigramWordNative(mNativeDict, codePoints, probability);
|
||||||
}
|
}
|
||||||
|
@ -290,7 +283,6 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
if (TextUtils.isEmpty(word0) || TextUtils.isEmpty(word1)) {
|
if (TextUtils.isEmpty(word0) || TextUtils.isEmpty(word1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runGCIfRequired();
|
|
||||||
final int[] codePoints0 = StringUtils.toCodePointArray(word0);
|
final int[] codePoints0 = StringUtils.toCodePointArray(word0);
|
||||||
final int[] codePoints1 = StringUtils.toCodePointArray(word1);
|
final int[] codePoints1 = StringUtils.toCodePointArray(word1);
|
||||||
addBigramWordsNative(mNativeDict, codePoints0, codePoints1, probability);
|
addBigramWordsNative(mNativeDict, codePoints0, codePoints1, probability);
|
||||||
|
@ -301,7 +293,6 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
if (TextUtils.isEmpty(word0) || TextUtils.isEmpty(word1)) {
|
if (TextUtils.isEmpty(word0) || TextUtils.isEmpty(word1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runGCIfRequired();
|
|
||||||
final int[] codePoints0 = StringUtils.toCodePointArray(word0);
|
final int[] codePoints0 = StringUtils.toCodePointArray(word0);
|
||||||
final int[] codePoints1 = StringUtils.toCodePointArray(word1);
|
final int[] codePoints1 = StringUtils.toCodePointArray(word1);
|
||||||
removeBigramWordsNative(mNativeDict, codePoints0, codePoints1);
|
removeBigramWordsNative(mNativeDict, codePoints0, codePoints1);
|
||||||
|
|
|
@ -273,6 +273,24 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
lastModifiedTime);
|
lastModifiedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runGCIfRequired() {
|
||||||
|
if (!ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) return;
|
||||||
|
if (mBinaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) {
|
||||||
|
if (setIsRegeneratingIfNotRegenerating()) {
|
||||||
|
getExecutor(mFilename).execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
mBinaryDictionary.flushWithGC();
|
||||||
|
} finally {
|
||||||
|
mFilenameDictionaryUpdateController.mIsRegenerating.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamically adds a word unigram to the dictionary. May overwrite an existing entry.
|
* Dynamically adds a word unigram to the dictionary. May overwrite an existing entry.
|
||||||
*/
|
*/
|
||||||
|
@ -282,7 +300,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
Log.w(TAG, "addWordDynamically is called for non-updatable dictionary: " + mFilename);
|
Log.w(TAG, "addWordDynamically is called for non-updatable dictionary: " + mFilename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
runGCIfRequired();
|
||||||
getExecutor(mFilename).execute(new Runnable() {
|
getExecutor(mFilename).execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -306,7 +324,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
+ mFilename);
|
+ mFilename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
runGCIfRequired();
|
||||||
getExecutor(mFilename).execute(new Runnable() {
|
getExecutor(mFilename).execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -330,7 +348,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
+ mFilename);
|
+ mFilename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
runGCIfRequired();
|
||||||
getExecutor(mFilename).execute(new Runnable() {
|
getExecutor(mFilename).execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
Loading…
Reference in New Issue