aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/research/MainLogBuffer.java
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2013-05-15 12:46:48 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-05-15 12:46:48 -0700
commit8facddba7df124efe0efad8dce661e08419f167a (patch)
tree4c4cf1523b4a6d6b8efdc7482326874383be7994 /java/src/com/android/inputmethod/research/MainLogBuffer.java
parent517f7865a2c4e2a0a3f0f16e9ae7a94ac718dbd1 (diff)
parent9b5965d452d55fd271dc14f2328b44da08c3cb67 (diff)
downloadlatinime-8facddba7df124efe0efad8dce661e08419f167a.tar.gz
latinime-8facddba7df124efe0efad8dce661e08419f167a.tar.xz
latinime-8facddba7df124efe0efad8dce661e08419f167a.zip
am 9b5965d4: am 1eb1af75: Merge "Fix looping logic bugs."
* commit '9b5965d452d55fd271dc14f2328b44da08c3cb67': Fix looping logic bugs.
Diffstat (limited to 'java/src/com/android/inputmethod/research/MainLogBuffer.java')
-rw-r--r--java/src/com/android/inputmethod/research/MainLogBuffer.java31
1 files changed, 19 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/research/MainLogBuffer.java b/java/src/com/android/inputmethod/research/MainLogBuffer.java
index 42ef5d3b6..9bdedbf6d 100644
--- a/java/src/com/android/inputmethod/research/MainLogBuffer.java
+++ b/java/src/com/android/inputmethod/research/MainLogBuffer.java
@@ -190,22 +190,30 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
}
protected final void publishLogUnitsAtFrontOfBuffer() {
+ // TODO: Refactor this method to require fewer passes through the LogUnits. Should really
+ // require only one pass.
ArrayList<LogUnit> logUnits = peekAtFirstNWords(N_GRAM_SIZE);
if (isSafeNGram(logUnits, N_GRAM_SIZE)) {
// Good n-gram at the front of the buffer. Publish it, disclosing details.
publish(logUnits, true /* canIncludePrivateData */);
shiftOutWords(N_GRAM_SIZE);
mNumWordsUntilSafeToSample = mNumWordsBetweenNGrams;
- } else {
- // No good n-gram at front, and buffer is full. Shift out up through the first logUnit
- // with associated words (or if there is none, all the existing logUnits).
- logUnits.clear();
- for (LogUnit logUnit = shiftOut(); logUnit != null && !logUnit.hasOneOrMoreWords();
- logUnit = shiftOut()) {
- logUnits.add(logUnit);
+ return;
+ }
+ // No good n-gram at front, and buffer is full. Shift out up through the first logUnit
+ // with associated words (or if there is none, all the existing logUnits).
+ logUnits.clear();
+ LogUnit logUnit = shiftOut();
+ while (logUnit != null) {
+ logUnits.add(logUnit);
+ final int numWords = logUnit.getNumWords();
+ if (numWords > 0) {
+ mNumWordsUntilSafeToSample = Math.max(0, mNumWordsUntilSafeToSample - numWords);
+ break;
}
- publish(logUnits, false /* canIncludePrivateData */);
+ logUnit = shiftOut();
}
+ publish(logUnits, false /* canIncludePrivateData */);
}
/**
@@ -222,12 +230,11 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
@Override
protected int shiftOutWords(final int numWords) {
- final int numWordContainingLogUnitsShiftedOut = super.shiftOutWords(numWords);
- mNumWordsUntilSafeToSample = Math.max(0, mNumWordsUntilSafeToSample
- - numWordContainingLogUnitsShiftedOut);
+ final int numWordsShiftedOut = super.shiftOutWords(numWords);
+ mNumWordsUntilSafeToSample = Math.max(0, mNumWordsUntilSafeToSample - numWordsShiftedOut);
if (DEBUG) {
Log.d(TAG, "wordsUntilSafeToSample now at " + mNumWordsUntilSafeToSample);
}
- return numWordContainingLogUnitsShiftedOut;
+ return numWordsShiftedOut;
}
}