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
74a84feb
Commit
74a84feb
authored
12 years ago
by
satok
Browse files
Options
Downloads
Patches
Plain Diff
Cache results of the spell checker
Change-Id: Ie11cd1b07e069474b140fbaae65fca703adc056f
parent
761b6bc1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+42
-2
42 additions, 2 deletions
...utmethod/latin/spellcheck/AndroidSpellCheckerService.java
with
42 additions
and
2 deletions
java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+
42
−
2
View file @
74a84feb
...
@@ -18,11 +18,11 @@ package com.android.inputmethod.latin.spellcheck;
...
@@ -18,11 +18,11 @@ package com.android.inputmethod.latin.spellcheck;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.content.res.Resources
;
import
android.preference.PreferenceManager
;
import
android.preference.PreferenceManager
;
import
android.service.textservice.SpellCheckerService
;
import
android.service.textservice.SpellCheckerService
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.Log
;
import
android.util.LruCache
;
import
android.view.textservice.SuggestionsInfo
;
import
android.view.textservice.SuggestionsInfo
;
import
android.view.textservice.TextInfo
;
import
android.view.textservice.TextInfo
;
...
@@ -455,6 +455,35 @@ public class AndroidSpellCheckerService extends SpellCheckerService
...
@@ -455,6 +455,35 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private
final
AndroidSpellCheckerService
mService
;
private
final
AndroidSpellCheckerService
mService
;
private
final
SuggestionsCache
mSuggestionsCache
=
new
SuggestionsCache
();
private
static
class
SuggestionsParams
{
public
final
String
[]
mSuggestions
;
public
final
int
mFlags
;
public
SuggestionsParams
(
String
[]
suggestions
,
int
flags
)
{
mSuggestions
=
suggestions
;
mFlags
=
flags
;
}
}
private
static
class
SuggestionsCache
{
private
static
final
int
MAX_CACHE_SIZE
=
50
;
// TODO: support bigram
private
final
LruCache
<
String
,
SuggestionsParams
>
mUnigramSuggestionsInfoCache
=
new
LruCache
<
String
,
SuggestionsParams
>(
MAX_CACHE_SIZE
);
public
SuggestionsParams
getSuggestionsFromCache
(
String
query
)
{
return
mUnigramSuggestionsInfoCache
.
get
(
query
);
}
public
void
putSuggestionsToCache
(
String
query
,
String
[]
suggestions
,
int
flags
)
{
if
(
suggestions
==
null
||
TextUtils
.
isEmpty
(
query
))
{
return
;
}
mUnigramSuggestionsInfoCache
.
put
(
query
,
new
SuggestionsParams
(
suggestions
,
flags
));
}
}
AndroidSpellCheckerSession
(
final
AndroidSpellCheckerService
service
)
{
AndroidSpellCheckerSession
(
final
AndroidSpellCheckerService
service
)
{
mService
=
service
;
mService
=
service
;
}
}
...
@@ -546,6 +575,15 @@ public class AndroidSpellCheckerService extends SpellCheckerService
...
@@ -546,6 +575,15 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final
int
suggestionsLimit
)
{
final
int
suggestionsLimit
)
{
try
{
try
{
final
String
text
=
textInfo
.
getText
();
final
String
text
=
textInfo
.
getText
();
final
SuggestionsParams
cachedSuggestionsParams
=
mSuggestionsCache
.
getSuggestionsFromCache
(
text
);
if
(
cachedSuggestionsParams
!=
null
)
{
if
(
DBG
)
{
Log
.
d
(
TAG
,
"Cache hit: "
+
text
+
", "
+
cachedSuggestionsParams
.
mFlags
);
}
return
new
SuggestionsInfo
(
cachedSuggestionsParams
.
mFlags
,
cachedSuggestionsParams
.
mSuggestions
);
}
if
(
shouldFilterOut
(
text
,
mScript
))
{
if
(
shouldFilterOut
(
text
,
mScript
))
{
DictAndProximity
dictInfo
=
null
;
DictAndProximity
dictInfo
=
null
;
...
@@ -628,7 +666,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
...
@@ -628,7 +666,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
?
SuggestionsInfoCompatUtils
?
SuggestionsInfoCompatUtils
.
getValueOf_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS
()
.
getValueOf_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS
()
:
0
);
:
0
);
return
new
SuggestionsInfo
(
flags
,
result
.
mSuggestions
);
final
SuggestionsInfo
retval
=
new
SuggestionsInfo
(
flags
,
result
.
mSuggestions
);
mSuggestionsCache
.
putSuggestionsToCache
(
text
,
result
.
mSuggestions
,
flags
);
return
retval
;
}
catch
(
RuntimeException
e
)
{
}
catch
(
RuntimeException
e
)
{
// Don't kill the keyboard if there is a bug in the spell checker
// Don't kill the keyboard if there is a bug in the spell checker
if
(
DBG
)
{
if
(
DBG
)
{
...
...
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