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
9d313c6c
Commit
9d313c6c
authored
11 years ago
by
Jean Chalard
Committed by
Android (Google) Code Review
11 years ago
Browse files
Options
Downloads
Plain Diff
Merge "[FD3] Split stackNodes into two methods."
parents
2c479e78
429db8d6
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
+37
-16
37 additions, 16 deletions
...oid/inputmethod/latin/makedict/BinaryDictInputOutput.java
with
37 additions
and
16 deletions
java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+
37
−
16
View file @
9d313c6c
...
...
@@ -384,13 +384,12 @@ public final class BinaryDictInputOutput {
/**
* Compute the maximum size of a node, assuming 3-byte addresses for everything, and caches
* it in the 'actualSize' member of the node
, then returns it
.
* it in the 'actualSize' member of the node.
*
* @param node the node to compute the maximum size of.
* @param options file format options.
* @return the size of the node.
*/
private
static
int
calculateNodeMaximumSize
(
final
Node
node
,
final
FormatOptions
options
)
{
private
static
void
calculateNodeMaximumSize
(
final
Node
node
,
final
FormatOptions
options
)
{
int
size
=
getGroupCountSize
(
node
);
for
(
CharGroup
g
:
node
.
mData
)
{
final
int
groupSize
=
getCharGroupMaximumSize
(
g
,
options
);
...
...
@@ -401,7 +400,6 @@ public final class BinaryDictInputOutput {
size
+=
FormatSpec
.
FORWARD_LINK_ADDRESS_SIZE
;
}
node
.
mCachedSize
=
size
;
return
size
;
}
/**
...
...
@@ -591,22 +589,48 @@ public final class BinaryDictInputOutput {
}
/**
* Computes the byte size of a list of nodes and updates each node cached position.
* Initializes the cached addresses of nodes from their size.
*
* @param flatNodes the array of nodes.
* @param formatOptions file format options.
* @return the byte size of the entire stack.
*/
private
static
int
initializeNodesCachedAddresses
(
final
ArrayList
<
Node
>
flatNodes
,
final
FormatOptions
formatOptions
)
{
int
nodeOffset
=
0
;
for
(
final
Node
n
:
flatNodes
)
{
n
.
mCachedAddressBeforeUpdate
=
nodeOffset
;
int
groupCountSize
=
getGroupCountSize
(
n
);
int
groupOffset
=
0
;
for
(
final
CharGroup
g
:
n
.
mData
)
{
g
.
mCachedAddress
=
groupCountSize
+
nodeOffset
+
groupOffset
;
groupOffset
+=
g
.
mCachedSize
;
}
final
int
nodeSize
=
groupCountSize
+
groupOffset
+
(
formatOptions
.
mSupportsDynamicUpdate
?
FormatSpec
.
FORWARD_LINK_ADDRESS_SIZE
:
0
);
nodeOffset
+=
n
.
mCachedSize
;
}
return
nodeOffset
;
}
/**
* Updates the cached addresses of nodes after recomputing their new positions.
*
* @param flatNodes the array of nodes.
* @param formatOptions file format options.
* @return the byte size of the entire stack.
*/
// TODO: rename this method when all it does is fill back the cached addresses before update
// with cached addresses after update.
private
static
int
stackNodes
(
final
ArrayList
<
Node
>
flatNodes
,
private
static
int
updateNodeCachedAddresses
(
final
ArrayList
<
Node
>
flatNodes
,
final
FormatOptions
formatOptions
)
{
int
nodeOffset
=
0
;
for
(
final
Node
n
:
flatNodes
)
{
n
.
mCachedAddressBeforeUpdate
=
n
.
mCachedAddressAfterUpdate
;
int
groupCountSize
=
getGroupCountSize
(
n
);
int
groupOffset
=
0
;
for
(
CharGroup
g
:
n
.
mData
)
{
for
(
final
CharGroup
g
:
n
.
mData
)
{
// TODO: just copy cached address after update into cached address before update
// when the two fields are separated.
g
.
mCachedAddress
=
groupCountSize
+
nodeOffset
+
groupOffset
;
groupOffset
+=
g
.
mCachedSize
;
}
...
...
@@ -614,6 +638,7 @@ public final class BinaryDictInputOutput {
+
(
formatOptions
.
mSupportsDynamicUpdate
?
FormatSpec
.
FORWARD_LINK_ADDRESS_SIZE
:
0
);
if
(
nodeSize
!=
n
.
mCachedSize
)
{
// TODO: remove this test when the addresses are separated
throw
new
RuntimeException
(
"Bug : Stored and computed node size differ"
);
}
if
(
nodeOffset
!=
n
.
mCachedAddressAfterUpdate
)
{
...
...
@@ -665,12 +690,8 @@ public final class BinaryDictInputOutput {
private
static
ArrayList
<
Node
>
computeAddresses
(
final
FusionDictionary
dict
,
final
ArrayList
<
Node
>
flatNodes
,
final
FormatOptions
formatOptions
)
{
// First get the worst possible sizes and offsets
int
offset
=
0
;
for
(
final
Node
n
:
flatNodes
)
{
n
.
mCachedAddressAfterUpdate
=
offset
;
offset
+=
calculateNodeMaximumSize
(
n
,
formatOptions
);
}
offset
=
stackNodes
(
flatNodes
,
formatOptions
);
for
(
final
Node
n
:
flatNodes
)
calculateNodeMaximumSize
(
n
,
formatOptions
);
final
int
offset
=
initializeNodesCachedAddresses
(
flatNodes
,
formatOptions
);
MakedictLog
.
i
(
"Compressing the array addresses. Original size : "
+
offset
);
MakedictLog
.
i
(
"(Recursively seen size : "
+
offset
+
")"
);
...
...
@@ -689,7 +710,7 @@ public final class BinaryDictInputOutput {
nodeStartOffset
+=
newNodeSize
;
changesDone
|=
changed
;
}
stackNod
es
(
flatNodes
,
formatOptions
);
updateNodeCachedAddress
es
(
flatNodes
,
formatOptions
);
++
passes
;
if
(
passes
>
MAX_PASSES
)
throw
new
RuntimeException
(
"Too many passes - probably a bug"
);
}
while
(
changesDone
);
...
...
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