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
d6834c81
Commit
d6834c81
authored
13 years ago
by
Jean Chalard
Committed by
Android (Google) Code Review
13 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Fix a bug with the string pool."
parents
6dde878d
a6e912cf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/latin/StringBuilderPool.java
+15
-1
15 additions, 1 deletion
.../src/com/android/inputmethod/latin/StringBuilderPool.java
java/src/com/android/inputmethod/latin/Suggest.java
+8
-1
8 additions, 1 deletion
java/src/com/android/inputmethod/latin/Suggest.java
with
23 additions
and
2 deletions
java/src/com/android/inputmethod/latin/StringBuilderPool.java
+
15
−
1
View file @
d6834c81
...
@@ -26,12 +26,20 @@ import java.util.List;
...
@@ -26,12 +26,20 @@ import java.util.List;
public
class
StringBuilderPool
{
public
class
StringBuilderPool
{
// Singleton
// Singleton
private
static
final
StringBuilderPool
sInstance
=
new
StringBuilderPool
();
private
static
final
StringBuilderPool
sInstance
=
new
StringBuilderPool
();
private
static
final
boolean
DEBUG
=
false
;
private
StringBuilderPool
()
{}
private
StringBuilderPool
()
{}
// TODO: Make this a normal array with a size of 20
// TODO: Make this a normal array with a size of 20
, or a ConcurrentQueue
private
final
List
<
StringBuilder
>
mPool
=
private
final
List
<
StringBuilder
>
mPool
=
Collections
.
synchronizedList
(
new
ArrayList
<
StringBuilder
>());
Collections
.
synchronizedList
(
new
ArrayList
<
StringBuilder
>());
public
static
StringBuilder
getStringBuilder
(
final
int
initialSize
)
{
public
static
StringBuilder
getStringBuilder
(
final
int
initialSize
)
{
// TODO: although the pool is synchronized, the following is not thread-safe.
// Two threads entering this at the same time could take the same size of the pool and the
// second to attempt removing this index from the pool would crash with an
// IndexOutOfBoundsException.
// At the moment this pool is only used in Suggest.java and only in one thread so it's
// okay. The simplest thing to do here is probably to replace the ArrayList with a
// ConcurrentQueue.
final
int
poolSize
=
sInstance
.
mPool
.
size
();
final
int
poolSize
=
sInstance
.
mPool
.
size
();
final
StringBuilder
sb
=
poolSize
>
0
?
(
StringBuilder
)
sInstance
.
mPool
.
remove
(
poolSize
-
1
)
final
StringBuilder
sb
=
poolSize
>
0
?
(
StringBuilder
)
sInstance
.
mPool
.
remove
(
poolSize
-
1
)
:
new
StringBuilder
(
initialSize
);
:
new
StringBuilder
(
initialSize
);
...
@@ -40,6 +48,12 @@ public class StringBuilderPool {
...
@@ -40,6 +48,12 @@ public class StringBuilderPool {
}
}
public
static
void
recycle
(
final
StringBuilder
garbage
)
{
public
static
void
recycle
(
final
StringBuilder
garbage
)
{
if
(
DEBUG
)
{
final
int
gid
=
garbage
.
hashCode
();
for
(
final
StringBuilder
q
:
sInstance
.
mPool
)
{
if
(
gid
==
q
.
hashCode
())
throw
new
RuntimeException
(
"Duplicate id "
+
gid
);
}
}
sInstance
.
mPool
.
add
(
garbage
);
sInstance
.
mPool
.
add
(
garbage
);
}
}
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/latin/Suggest.java
+
8
−
1
View file @
d6834c81
...
@@ -284,7 +284,14 @@ public class Suggest implements Dictionary.WordCallback {
...
@@ -284,7 +284,14 @@ public class Suggest implements Dictionary.WordCallback {
}
}
protected
void
addBigramToSuggestions
(
CharSequence
bigram
)
{
protected
void
addBigramToSuggestions
(
CharSequence
bigram
)
{
mSuggestions
.
add
(
bigram
);
// TODO: Try to be a little more shrewd with resource allocation.
// At the moment we copy this object because the StringBuilders are pooled (see
// StringBuilderPool.java) and when we are finished using mSuggestions and
// mBigramSuggestions we will take everything from both and insert them back in the
// pool, so we can't allow the same object to be in both lists at the same time.
final
StringBuilder
sb
=
StringBuilderPool
.
getStringBuilder
(
getApproxMaxWordLength
());
sb
.
append
(
bigram
);
mSuggestions
.
add
(
sb
);
}
}
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
...
...
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