diff options
author | 2013-07-24 01:40:56 -0700 | |
---|---|---|
committer | 2013-07-24 01:40:56 -0700 | |
commit | 4322d18832b75d533a92c18110dba5424554f841 (patch) | |
tree | d905b513894b9a07c94f5eb9c6ee42c55ea20372 /java | |
parent | 3014ff643fbe2707eaaa98914b2581a11669ccd9 (diff) | |
parent | 9d313c6ce96bbf47db7651445031793765094d7e (diff) | |
download | latinime-4322d18832b75d533a92c18110dba5424554f841.tar.gz latinime-4322d18832b75d533a92c18110dba5424554f841.tar.xz latinime-4322d18832b75d533a92c18110dba5424554f841.zip |
am 9d313c6c: Merge "[FD3] Split stackNodes into two methods."
* commit '9d313c6ce96bbf47db7651445031793765094d7e':
[FD3] Split stackNodes into two methods.
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java index 2f5e847f7..a54344ab5 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java @@ -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; } - stackNodes(flatNodes, formatOptions); + updateNodeCachedAddresses(flatNodes, formatOptions); ++passes; if (passes > MAX_PASSES) throw new RuntimeException("Too many passes - probably a bug"); } while (changesDone); |