aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorYuichiro Hanada <yhanada@google.com>2013-08-16 04:31:47 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-08-16 04:31:47 -0700
commit2b16830322a4a17140d8c6d9f8136ccc05cc5d19 (patch)
tree86cf9b6b083f67033e9b6034aa8eacb7e79e9e88 /java/src
parent861aa7beed2f71374e29b8275ef1bfea28e1b914 (diff)
parente72c4e5fc7531f23f5806efed91aafe5d1ba2d1f (diff)
downloadlatinime-2b16830322a4a17140d8c6d9f8136ccc05cc5d19.tar.gz
latinime-2b16830322a4a17140d8c6d9f8136ccc05cc5d19.tar.xz
latinime-2b16830322a4a17140d8c6d9f8136ccc05cc5d19.zip
am e72c4e5f: Remove a static buffer for thread safety.
* commit 'e72c4e5fc7531f23f5806efed91aafe5d1ba2d1f': Remove a static buffer for thread safety.
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java16
1 files changed, 4 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
index 046c5b5dc..8d68c7ed6 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
@@ -457,16 +457,13 @@ public final class BinaryDictDecoder {
return result;
}
- // TODO: static!? This will behave erratically when used in multi-threaded code.
- // We need to fix this
- private static int[] sGetWordBuffer = new int[FormatSpec.MAX_WORD_LENGTH];
@SuppressWarnings("unused")
private static WeightedString getWordAtAddressWithParentAddress(
final FusionDictionaryBufferInterface buffer, final int headerSize, final int address,
final FormatOptions options) {
int currentAddress = address;
- int index = FormatSpec.MAX_WORD_LENGTH - 1;
int frequency = Integer.MIN_VALUE;
+ final StringBuilder builder = new StringBuilder();
// the length of the path from the root to the leaf is limited by MAX_WORD_LENGTH
for (int count = 0; count < FormatSpec.MAX_WORD_LENGTH; ++count) {
CharGroupInfo currentInfo;
@@ -482,17 +479,12 @@ public final class BinaryDictDecoder {
}
} while (BinaryDictIOUtils.isMovedGroup(currentInfo.mFlags, options));
if (Integer.MIN_VALUE == frequency) frequency = currentInfo.mFrequency;
- for (int i = 0; i < currentInfo.mCharacters.length; ++i) {
- sGetWordBuffer[index--] =
- currentInfo.mCharacters[currentInfo.mCharacters.length - i - 1];
- }
+ builder.insert(0,
+ new String(currentInfo.mCharacters, 0, currentInfo.mCharacters.length));
if (currentInfo.mParentAddress == FormatSpec.NO_PARENT_ADDRESS) break;
currentAddress = currentInfo.mParentAddress + currentInfo.mOriginalAddress;
}
-
- return new WeightedString(
- new String(sGetWordBuffer, index + 1, FormatSpec.MAX_WORD_LENGTH - index - 1),
- frequency);
+ return new WeightedString(builder.toString(), frequency);
}
private static WeightedString getWordAtAddressWithoutParentAddress(