Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
805fed49
Commit
805fed49
authored
12 years ago
by
Jean Chalard
Committed by
Android (Google) Code Review
12 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Fix binary reading code performance."
parents
fe4d13cb
1d80a7f3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+10
-1
10 additions, 1 deletion
...oid/inputmethod/latin/makedict/BinaryDictInputOutput.java
with
10 additions
and
1 deletion
java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+
10
−
1
View file @
805fed49
...
@@ -1142,6 +1142,12 @@ public class BinaryDictInputOutput {
...
@@ -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.
* Finds, as a string, the word at the address passed as an argument.
*
*
...
@@ -1151,8 +1157,10 @@ public class BinaryDictInputOutput {
...
@@ -1151,8 +1157,10 @@ public class BinaryDictInputOutput {
* @return the word, as a string.
* @return the word, as a string.
* @throws IOException if the file can't be read.
* @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
{
int
address
)
throws
IOException
{
final
String
cachedString
=
wordCache
.
get
(
address
);
if
(
null
!=
cachedString
)
return
cachedString
;
final
long
originalPointer
=
source
.
getFilePointer
();
final
long
originalPointer
=
source
.
getFilePointer
();
source
.
seek
(
headerSize
);
source
.
seek
(
headerSize
);
final
int
count
=
readCharGroupCount
(
source
);
final
int
count
=
readCharGroupCount
(
source
);
...
@@ -1191,6 +1199,7 @@ public class BinaryDictInputOutput {
...
@@ -1191,6 +1199,7 @@ public class BinaryDictInputOutput {
}
}
}
}
source
.
seek
(
originalPointer
);
source
.
seek
(
originalPointer
);
wordCache
.
put
(
address
,
result
);
return
result
;
return
result
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment