diff options
author | 2013-05-07 16:23:39 -0700 | |
---|---|---|
committer | 2013-05-07 16:23:39 -0700 | |
commit | 9b5965d452d55fd271dc14f2328b44da08c3cb67 (patch) | |
tree | 2debacc28c50bbfef273e2957b293f0b76ea1f80 /java/src/com/android/inputmethod/research/FixedLogBuffer.java | |
parent | f7937a944095eb1dedd502fe4ea360198df861e6 (diff) | |
parent | 1eb1af75a7f19ea3b544205d42a3890781021a0b (diff) | |
download | latinime-9b5965d452d55fd271dc14f2328b44da08c3cb67.tar.gz latinime-9b5965d452d55fd271dc14f2328b44da08c3cb67.tar.xz latinime-9b5965d452d55fd271dc14f2328b44da08c3cb67.zip |
am 1eb1af75: Merge "Fix looping logic bugs."
* commit '1eb1af75a7f19ea3b544205d42a3890781021a0b':
Fix looping logic bugs.
Diffstat (limited to '')
-rw-r--r-- | java/src/com/android/inputmethod/research/FixedLogBuffer.java | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/research/FixedLogBuffer.java b/java/src/com/android/inputmethod/research/FixedLogBuffer.java index 4249af544..8b64de8ae 100644 --- a/java/src/com/android/inputmethod/research/FixedLogBuffer.java +++ b/java/src/com/android/inputmethod/research/FixedLogBuffer.java @@ -65,6 +65,7 @@ public class FixedLogBuffer extends LogBuffer { final int numWordsIncoming = newLogUnit.getNumWords(); if (mNumActualWords >= mWordCapacity) { // Give subclass a chance to handle the buffer full condition by shifting out logUnits. + // TODO: Tell onBufferFull() how much space it needs to make to avoid forced eviction. onBufferFull(); // If still full, evict. if (mNumActualWords >= mWordCapacity) { @@ -119,21 +120,19 @@ public class FixedLogBuffer extends LogBuffer { /** * Remove LogUnits from the front of the LogBuffer until {@code numWords} have been removed. * - * If there are less than {@code numWords} word-containing {@link LogUnit}s, shifts out - * all {@code LogUnit}s in the buffer. + * If there are less than {@code numWords} in the buffer, shifts out all {@code LogUnit}s. * - * @param numWords the minimum number of word-containing {@link LogUnit}s to shift out - * @return the number of actual {@code LogUnit}s shifted out + * @param numWords the minimum number of words in {@link LogUnit}s to shift out + * @return the number of actual words LogUnit}s shifted out */ protected int shiftOutWords(final int numWords) { - int numWordContainingLogUnitsShiftedOut = 0; - for (LogUnit logUnit = shiftOut(); logUnit != null - && numWordContainingLogUnitsShiftedOut < numWords; logUnit = shiftOut()) { - if (logUnit.hasOneOrMoreWords()) { - numWordContainingLogUnitsShiftedOut += logUnit.getNumWords(); - } - } - return numWordContainingLogUnitsShiftedOut; + int numWordsShiftedOut = 0; + do { + final LogUnit logUnit = shiftOut(); + if (logUnit == null) break; + numWordsShiftedOut += logUnit.getNumWords(); + } while (numWordsShiftedOut < numWords); + return numWordsShiftedOut; } public void shiftOutAll() { |