aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-04-23 23:39:37 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-23 23:39:37 -0700
commit805fed49e1b477a90ada4151dc4df89e5857c7e9 (patch)
tree84e73622cc3defebb2a4fb0b64895589e8354463 /java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
parentfe4d13cbcb1fde041dc319aa25bae68b6dabb902 (diff)
parent1d80a7f395290cd0e7344210bb3960f685059264 (diff)
downloadlatinime-805fed49e1b477a90ada4151dc4df89e5857c7e9.tar.gz
latinime-805fed49e1b477a90ada4151dc4df89e5857c7e9.tar.xz
latinime-805fed49e1b477a90ada4151dc4df89e5857c7e9.zip
Merge "Fix binary reading code performance."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index b1bee4e65..cc98010fb 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -1142,6 +1142,12 @@ public class BinaryDictInputOutput {
}
}
+ // The word cache here is a stopgap bandaid to help the catastrophic performance
+ // of this method. Since it performs direct, unbuffered random access to the file and
+ // may be called hundreds of thousands of times, the resulting performance is not
+ // reasonable without some kind of cache. Thus:
+ // TODO: perform buffered I/O here and in other places in the code.
+ private static TreeMap<Integer, String> wordCache = new TreeMap<Integer, String>();
/**
* Finds, as a string, the word at the address passed as an argument.
*
@@ -1151,8 +1157,10 @@ public class BinaryDictInputOutput {
* @return the word, as a string.
* @throws IOException if the file can't be read.
*/
- private static String getWordAtAddress(RandomAccessFile source, long headerSize,
+ private static String getWordAtAddress(final RandomAccessFile source, final long headerSize,
int address) throws IOException {
+ final String cachedString = wordCache.get(address);
+ if (null != cachedString) return cachedString;
final long originalPointer = source.getFilePointer();
source.seek(headerSize);
final int count = readCharGroupCount(source);
@@ -1191,6 +1199,7 @@ public class BinaryDictInputOutput {
}
}
source.seek(originalPointer);
+ wordCache.put(address, result);
return result;
}