[FOray-commit] SF.net SVN: foray:[10654] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2009-03-12 18:25:43
|
Revision: 10654
http://foray.svn.sourceforge.net/foray/?rev=10654&view=rev
Author: victormote
Date: 2009-03-12 18:25:16 +0000 (Thu, 12 Mar 2009)
Log Message:
-----------
1. Use the new ByteVectorPacked class to simplify the storage of the pattern values.
Modified Paths:
--------------
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenationTree.java
trunk/foray/lib/foray-hyphen-0.4-rsrc.jar
Modified: trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenationTree.java
===================================================================
--- trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenationTree.java 2009-03-12 17:43:26 UTC (rev 10653)
+++ trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenationTree.java 2009-03-12 18:25:16 UTC (rev 10654)
@@ -33,7 +33,7 @@
package org.foray.hyphen;
-import org.foray.common.ByteVector;
+import org.foray.common.ByteVectorPacked;
import org.foray.common.CharVector;
import org.foray.common.StringUtil;
import org.foray.common.WKConstants;
@@ -98,6 +98,9 @@
* is appended */
private static final int QTY_MARKER_CHARS = 3;
+ /** Value indicating the termination of a pattern value in the vector. */
+ private static final byte PATTERN_VALUES_TERMINATOR = (byte) 0xF;
+
/** The source of this tree. Used by testing routines to make sure that the serialized versions
* are getting used. */
private transient Source source;
@@ -126,7 +129,7 @@
* The pattern values themselves are stored as bytes, and are expected to be
* in the range of 0x01 through 0x05.</p>
*/
- private ByteVector patternValues = new ByteVector();
+ private ByteVectorPacked patternValues = new ByteVectorPacked();
/** The hyphenation exceptions. */
private Map<String, Hyphenation4a> exceptions
@@ -158,36 +161,16 @@
* @see #unpackValues(int)
*/
private int packValues(final String values) {
- final int stringLength = values.length();
- /* Bytes needed is half the length of the String, plus one byte for the
- * zero terminator, ... */
- int bytesNeeded = (stringLength >> 1) + 1;
- if ((stringLength & 1) == 1) {
- /* ... unless the String size is odd, in which case we need to round
- * up. */
- bytesNeeded ++;
- }
- final int offset = this.patternValues.alloc(bytesNeeded);
- for (int stringIndex = 0; stringIndex < stringLength; stringIndex++) {
+ final int start = this.patternValues.length();
+ for (int stringIndex = 0; stringIndex < values.length(); stringIndex++) {
final byte packedValue = (byte) ((values.charAt(stringIndex)
- '0' + 1) & WKConstants.MAX_4_BIT_UNSIGNED_BYTE);
- final int packedIndex = (stringIndex >> 1) + offset;
- if ((stringIndex & 1) == 1) {
- /* If the index is odd, place in the low-order bits. */
- final byte currentValue = this.patternValues.get(packedIndex);
- final byte newValue = (byte) (currentValue | packedValue);
- this.patternValues.set(packedIndex, newValue);
- } else {
- /* If the index is even, place in the high-order bits. */
- final byte newValue = (byte) (packedValue
- << WKConstants.BITS_PER_NIBBLE);
- this.patternValues.set(packedIndex, newValue);
- }
+ this.patternValues.add(packedValue);
}
- /* Add the null terminator. */
- this.patternValues.set(bytesNeeded - 1 + offset, (byte) 0);
+ /* Add the termination marker. */
+ this.patternValues.add(HyphenationTree.PATTERN_VALUES_TERMINATOR);
- return offset;
+ return start;
}
/**
@@ -229,19 +212,10 @@
final StringBuilder buf = new StringBuilder();
int packedIndex = start;
byte packedValue = this.patternValues.get(packedIndex++);
- while (packedValue != 0) {
- /* Unpack the high-order nibble. */
- char c = (char) ((packedValue >>> WKConstants.BITS_PER_NIBBLE) - 1);
+ while (packedValue != HyphenationTree.PATTERN_VALUES_TERMINATOR) {
+ final char c = (char) (packedValue - 1);
buf.append(c);
- /* Unpack the low-order nibble. */
- c = (char) (packedValue & WKConstants.MAX_4_BIT_UNSIGNED_BYTE);
- if (c == 0) {
- break;
- }
- c = (char) (c - 1);
- buf.append(c);
-
/* Load the next byte. */
packedValue = this.patternValues.get(packedIndex++);
}
Modified: trunk/foray/lib/foray-hyphen-0.4-rsrc.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|