sboag 00/10/17 21:36:48
Modified: java/src makexslt4j
java/src/org/apache/xalan/templates AVT.java AVTPart.java
AVTPartSimple.java AVTPartXPath.java
ElemNumber.java StylesheetComposed.java
TemplateList.java
TemplateSubPatternAssociation.java
java/src/org/apache/xalan/transformer TransformerImpl.java
java/src/org/apache/xalan/utils StringBufferPool.java
java/src/org/apache/xml/serialize/transition
HTMLSerializer.java IndentPrinter.java
java/src/org/apache/xpath DOMHelper.java XPathContext.java
Added: java/src/org/apache/xalan/utils FastStringBuffer.java
java/src/org/apache/xml/serialize/transition
FastStringBuffer.java
Log:
Added FastStringBuffer class, since StringBuffer is pretty sad for reuse.
Optimized loop in getTemplates so it doesn't do the pushes and pops of the
context inside the loop.
Revision Changes Path
1.24 +2 -0 xml-xalan/java/src/makexslt4j
Index: makexslt4j
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/makexslt4j,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- makexslt4j 2000/10/17 19:51:27 1.23
+++ makexslt4j 2000/10/18 04:36:42 1.24
@@ -241,6 +241,7 @@
org$(PATHSEP)apache$(PATHSEP)xalan$(PATHSEP)utils$(PATHSEP)NodeConsumer.java \
org$(PATHSEP)apache$(PATHSEP)xalan$(PATHSEP)utils$(PATHSEP)WrappedRuntimeException.java
\
org$(PATHSEP)apache$(PATHSEP)xalan$(PATHSEP)utils$(PATHSEP)XMLCharacterRecognizer.java
\
+
org$(PATHSEP)apache$(PATHSEP)xalan$(PATHSEP)utils$(PATHSEP)FastStringBuffer.java
\
org$(PATHSEP)apache$(PATHSEP)xalan$(PATHSEP)utils$(PATHSEP)StringBufferPool.java
\
org$(PATHSEP)apache$(PATHSEP)xalan$(PATHSEP)xslt$(PATHSEP)Process.java \
org$(PATHSEP)apache$(PATHSEP)trax$(PATHSEP)Examples.java \
@@ -325,6 +326,7 @@
org$(PATHSEP)xml$(PATHSEP)sax$(PATHSEP)helpers$(PATHSEP)XMLFilterImpl.java
\
org$(PATHSEP)xml$(PATHSEP)sax$(PATHSEP)helpers$(PATHSEP)XMLReaderAdapter.java \
org$(PATHSEP)xml$(PATHSEP)sax$(PATHSEP)helpers$(PATHSEP)XMLReaderFactory.java \
+
org$(PATHSEP)apache$(PATHSEP)xml$(PATHSEP)serialize$(PATHSEP)transition$(PATHSEP)FastStringBuffer.java
\
org$(PATHSEP)apache$(PATHSEP)xml$(PATHSEP)serialize$(PATHSEP)transition$(PATHSEP)BaseMarkupSerializer.java
\
org$(PATHSEP)apache$(PATHSEP)xml$(PATHSEP)serialize$(PATHSEP)transition$(PATHSEP)ElementState.java
\
org$(PATHSEP)apache$(PATHSEP)xml$(PATHSEP)serialize$(PATHSEP)transition$(PATHSEP)Encodings.java
\
1.6 +5 -4 xml-xalan/java/src/org/apache/xalan/templates/AVT.java
Index: AVT.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVT.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AVT.java 2000/10/17 19:01:18 1.5
+++ AVT.java 2000/10/18 04:36:42 1.6
@@ -60,6 +60,7 @@
import java.util.Vector;
import java.util.StringTokenizer;
import org.apache.xalan.utils.StringBufferPool;
+import org.apache.xalan.utils.FastStringBuffer;
import org.xml.sax.SAXException;
import org.xml.sax.ErrorHandler;
import org.apache.xpath.XPathContext;
@@ -150,8 +151,8 @@
}
else
{
- StringBuffer buffer = StringBufferPool.get();
- StringBuffer exprBuffer = StringBufferPool.get();
+ FastStringBuffer buffer = StringBufferPool.get();
+ FastStringBuffer exprBuffer = StringBufferPool.get();
try
{
m_parts = new Vector(nTokens+1);
@@ -338,7 +339,7 @@
}
else if(null != m_parts)
{
- StringBuffer buf = StringBufferPool.get();
+ FastStringBuffer buf = StringBufferPool.get();
String s;
try
{
@@ -373,7 +374,7 @@
org.apache.xalan.utils.PrefixResolver nsNode)
throws org.xml.sax.SAXException
{
- StringBuffer buf = StringBufferPool.get();
+ FastStringBuffer buf = StringBufferPool.get();
try
{
if(null != m_simpleString)
1.4 +2 -1
xml-xalan/java/src/org/apache/xalan/templates/AVTPart.java
Index: AVTPart.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVTPart.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AVTPart.java 2000/08/09 04:26:40 1.3
+++ AVTPart.java 2000/10/18 04:36:42 1.4
@@ -58,6 +58,7 @@
import org.w3c.dom.*;
import org.apache.xpath.XPathContext;
+import org.apache.xalan.utils.FastStringBuffer;
/**
* <meta name="usage" content="internal"/>
@@ -86,7 +87,7 @@
* @param nsNode The current namespace context (stylesheet tree context).
* @param NodeList The current Context Node List.
*/
- public abstract void evaluate(XPathContext xctxt, StringBuffer buf, Node
context,
+ public abstract void evaluate(XPathContext xctxt, FastStringBuffer buf,
Node context,
org.apache.xalan.utils.PrefixResolver nsNode)
throws org.xml.sax.SAXException;
1.4 +2 -1
xml-xalan/java/src/org/apache/xalan/templates/AVTPartSimple.java
Index: AVTPartSimple.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVTPartSimple.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AVTPartSimple.java 2000/08/09 04:26:40 1.3
+++ AVTPartSimple.java 2000/10/18 04:36:43 1.4
@@ -58,6 +58,7 @@
import org.w3c.dom.*;
import org.apache.xpath.XPathContext;
+import org.apache.xalan.utils.FastStringBuffer;
/**
* <meta name="usage" content="internal"/>
@@ -94,7 +95,7 @@
* @param nsNode The current namespace context (stylesheet tree context).
* @param NodeList The current Context Node List.
*/
- public void evaluate(XPathContext xctxt, StringBuffer buf, Node context,
+ public void evaluate(XPathContext xctxt, FastStringBuffer buf, Node
context,
org.apache.xalan.utils.PrefixResolver nsNode)
{
buf.append(m_val);
1.4 +2 -1
xml-xalan/java/src/org/apache/xalan/templates/AVTPartXPath.java
Index: AVTPartXPath.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVTPartXPath.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AVTPartXPath.java 2000/08/09 04:26:40 1.3
+++ AVTPartXPath.java 2000/10/18 04:36:43 1.4
@@ -60,6 +60,7 @@
import org.apache.xpath.objects.XObject;
import org.apache.xpath.XPathContext;
import org.apache.xpath.compiler.XPathParser;
+import org.apache.xalan.utils.FastStringBuffer;
import org.w3c.dom.*;
/**
@@ -109,7 +110,7 @@
* @param nsNode The current namespace context (stylesheet tree context).
* @param NodeList The current Context Node List.
*/
- public void evaluate(XPathContext xctxt, StringBuffer buf, Node context,
+ public void evaluate(XPathContext xctxt, FastStringBuffer buf, Node
context,
org.apache.xalan.utils.PrefixResolver nsNode)
throws org.xml.sax.SAXException
{
1.7 +8 -5
xml-xalan/java/src/org/apache/xalan/templates/ElemNumber.java
Index: ElemNumber.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemNumber.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ElemNumber.java 2000/10/17 19:03:32 1.6
+++ ElemNumber.java 2000/10/18 04:36:43 1.7
@@ -69,6 +69,7 @@
import org.apache.xpath.compiler.XPathParser;
import org.apache.xalan.utils.QName;
import org.apache.xalan.utils.StringBufferPool;
+import org.apache.xalan.utils.FastStringBuffer;
import org.apache.xalan.res.*;
import org.apache.xalan.transformer.DecimalToRoman;
import org.apache.xalan.transformer.CountersTable;
@@ -890,7 +891,7 @@
throws SAXException
{
String numStr;
- StringBuffer formattedNumber = StringBufferPool.get();
+ FastStringBuffer formattedNumber = StringBufferPool.get();
try
{
int nNumbers = list.length, numberWidth = 1;
@@ -982,7 +983,9 @@
else if(null != lastSep && !isFirstToken)
formattedNumber.append(lastSep);
- getFormattedNumber(transformer, contextNode, numberType,
numberWidth, list[i], formattedNumber);
+ getFormattedNumber(transformer, contextNode,
+ numberType, numberWidth,
+ list[i], formattedNumber);
isFirstToken = false; // After the first pass, this
should be false
} // end for loop
@@ -1020,7 +1023,7 @@
char numberType,
int numberWidth,
int listElement,
- StringBuffer formattedNumber)
+ FastStringBuffer formattedNumber)
throws org.xml.sax.SAXException
{
DecimalFormat formatter = getNumberFormatter(transformer, contextNode);
@@ -1049,7 +1052,7 @@
alphabet= (char[]) thisBundle.getObject(Constants.LANG_ALPHABET);
m_alphaCountTable = alphabet;
}
- StringBuffer stringBuf = StringBufferPool.get();
+ FastStringBuffer stringBuf = StringBufferPool.get();
try
{
int2alphaCount(listElement, m_alphaCountTable, stringBuf);
@@ -1224,7 +1227,7 @@
* Note that the radix of the conversion is inferred from the size
* of the table.
*/
- protected void int2alphaCount(int val, char [] aTable, StringBuffer
stringBuf)
+ protected void int2alphaCount(int val, char [] aTable, FastStringBuffer
stringBuf)
{
int radix = aTable.length;
1.12 +4 -0
xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java
Index: StylesheetComposed.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- StylesheetComposed.java 2000/10/17 19:08:03 1.11
+++ StylesheetComposed.java 2000/10/18 04:36:43 1.12
@@ -566,6 +566,10 @@
* The "xsl:template" properties.
*/
private transient TemplateList m_templateList = new TemplateList(this);
+ public final TemplateList getTemplateListComposed()
+ {
+ return m_templateList;
+ }
/**
* Aggregate the list of templates and included templates into a single
list.
1.13 +18 -9
xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java
Index: TemplateList.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TemplateList.java 2000/10/17 18:59:53 1.12
+++ TemplateList.java 2000/10/18 04:36:43 1.13
@@ -469,18 +469,27 @@
{
TemplateSubPatternAssociation head = getHead(xctxt, targetNode);
- while (null != head)
+ if(null != head)
{
- if(head.matches(xctxt, targetNode, mode))
+ try
{
- if(quietConflictWarnings)
- checkConflicts(head, xctxt, targetNode, mode);
- if(DEBUG)
- System.out.println("return("+head.getTargetString()
- +", "+head.getPattern()+")");
- return head.getTemplate();
+ xctxt.pushCurrentNodeAndExpression(targetNode, targetNode);
+ do
+ {
+ if(head.m_stepPattern.execute(xctxt) != NodeTest.SCORE_NONE)
+ {
+ if(quietConflictWarnings)
+ checkConflicts(head, xctxt, targetNode, mode);
+ return head.getTemplate();
+ }
+ head = head.getNext();
+ }
+ while (null != head);
}
- head = head.getNext();
+ finally
+ {
+ xctxt.popCurrentNodeAndExpression();
+ }
}
StylesheetComposed stylesheet = getStylesheet().getStylesheetComposed();
1.2 +1 -1
xml-xalan/java/src/org/apache/xalan/templates/TemplateSubPatternAssociation.java
Index: TemplateSubPatternAssociation.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/TemplateSubPatternAssociation.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TemplateSubPatternAssociation.java 2000/10/17 19:00:35 1.1
+++ TemplateSubPatternAssociation.java 2000/10/18 04:36:44 1.2
@@ -72,7 +72,7 @@
*/
class TemplateSubPatternAssociation implements Serializable, Cloneable
{
- private StepPattern m_stepPattern;
+ StepPattern m_stepPattern;
private int m_posInStylesheet;
private String m_pattern;
private ElemTemplate m_template;
1.38 +4 -4
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- TransformerImpl.java 2000/10/17 20:30:09 1.37
+++ TransformerImpl.java 2000/10/18 04:36:46 1.38
@@ -82,6 +82,7 @@
import org.apache.xalan.templates.ElemVariable;
import org.apache.xalan.templates.ElemParam;
import org.apache.xalan.templates.ElemTemplate;
+import org.apache.xalan.templates.TemplateList;
import org.apache.xalan.trace.TraceManager;
@@ -1321,10 +1322,9 @@
try
{
xctxt.setNamespaceContext(xslInstruction);
-
- template = stylesheetTree.getTemplateComposed(xctxt,
- child, mode,
-
getQuietConflictWarnings());
+
+ TemplateList tl = stylesheetTree.getTemplateListComposed();
+ template = tl.getTemplate(xctxt, child, mode,
m_quietConflictWarnings);
}
finally
{
1.2 +4 -4
xml-xalan/java/src/org/apache/xalan/utils/StringBufferPool.java
Index: StringBufferPool.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/utils/StringBufferPool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StringBufferPool.java 2000/10/17 19:21:41 1.1
+++ StringBufferPool.java 2000/10/18 04:36:46 1.2
@@ -3,14 +3,14 @@
public class StringBufferPool
{
private static ObjectPool m_stringBufPool
- = new ObjectPool(java.lang.StringBuffer.class);
+ = new ObjectPool(org.apache.xalan.utils.FastStringBuffer.class);
- public static StringBuffer get()
+ public static FastStringBuffer get()
{
- return (StringBuffer)m_stringBufPool.getInstance();
+ return (FastStringBuffer)m_stringBufPool.getInstance();
}
- public static void free(StringBuffer sb)
+ public static void free(FastStringBuffer sb)
{
m_stringBufPool.freeInstance(sb);
sb.setLength(0);
1.1
xml-xalan/java/src/org/apache/xalan/utils/FastStringBuffer.java
Index: FastStringBuffer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.utils;
/**
* Bare-bones, unsafe, fast string buffer.
*/
public class FastStringBuffer
{
public int m_blocksize;
public char m_map[]; // don't hold on to a reference!
public int m_firstFree = 0;
public int m_mapSize;
/**
* Construct a IntVector, using the given block size.
*/
public FastStringBuffer()
{
m_blocksize = 1024;
m_mapSize = 1024;
m_map = new char[1024];
}
/**
* Construct a IntVector, using the given block size.
*/
public FastStringBuffer(int blocksize)
{
m_blocksize = blocksize;
m_mapSize = blocksize;
m_map = new char[blocksize];
}
/**
* Get the length of the list.
*/
public final int size()
{
return m_firstFree;
}
public final int length()
{
return m_firstFree;
}
public final void reset()
{
m_firstFree = 0;
}
public final void setLength(int l)
{
m_firstFree = l;
}
public final String toString()
{
return new String(m_map, 0, m_firstFree);
}
private final void ensureSize(int newSize)
{
if((m_firstFree+newSize) >= m_mapSize)
{
if(m_blocksize > newSize)
m_mapSize+=m_blocksize;
else
m_mapSize+=(newSize+m_blocksize);
char newMap[] = new char[m_mapSize];
System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
m_map = newMap;
}
}
/**
* Append a int onto the vector.
*/
public final void append(char value)
{
ensureSize(1);
m_map[m_firstFree] = value;
m_firstFree++;
}
/**
* Append a int onto the vector.
*/
public final void append(String value)
{
int len = value.length();
ensureSize(len);
value.getChars(0, len, m_map, m_firstFree);
m_firstFree+=len;
}
/**
* Append a int onto the vector.
*/
public final void append(StringBuffer value)
{
int len = value.length();
ensureSize(len);
value.getChars(0, len, m_map, m_firstFree);
m_firstFree+=len;
}
public final void append( char[] chars, int start, int length )
{
ensureSize(length);
System.arraycopy(chars, start, m_map, m_firstFree, length);
m_firstFree+=length;
}
public final void append( FastStringBuffer value )
{
int length = value.m_firstFree;
ensureSize(length);
System.arraycopy(value.m_map, 0, m_map, m_firstFree, length);
m_firstFree+=length;
}
}
1.6 +20 -20
xml-xalan/java/src/org/apache/xml/serialize/transition/HTMLSerializer.java
Index: HTMLSerializer.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serialize/transition/HTMLSerializer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLSerializer.java 2000/10/17 19:29:08 1.5
+++ HTMLSerializer.java 2000/10/18 04:36:47 1.6
@@ -117,7 +117,7 @@
* </ul>
*
*
- * @version $Revision: 1.5 $ $Date: 2000/10/17 19:29:08 $
+ * @version $Revision: 1.6 $ $Date: 2000/10/18 04:36:47 $
* @author <a href="mailto:[EMAIL PROTECTED]">Assaf Arkin</a>
* @see Serializer
*/
@@ -390,29 +390,29 @@
// Handle SCRIPT and STYLE specifically by changing the
// state of the current element to CDATA (XHTML) or
// unescaped (HTML).
- if ( htmlName != null && ( rawName.equalsIgnoreCase( "SCRIPT" ) ||
- rawName.equalsIgnoreCase( "STYLE" ) ) ) {
+ if(null != htmlName)
+ {
+ String rawNameU = rawName.toUpperCase();
+ if ( rawNameU.equals( "SCRIPT" ) ||
+ rawNameU.equals( "STYLE" )) {
if ( _xhtml ) {
- // XHTML: Print contents as CDATA section
- state.doCData = true;
+ // XHTML: Print contents as CDATA section
+ state.doCData = true;
} else {
- // HTML: Print contents unescaped
- state.unescaped = true;
+ // HTML: Print contents unescaped
+ state.unescaped = true;
}
+ }
+ if (rawName.equalsIgnoreCase( "HEAD" ))
+ {
+ _printer.printText( '>' );
+ // Insert Meta tag here
+ _printer.breakLine();
+ _printer.printText( "<META http-equiv=\"Content-Type\"
content=\"text/html; charset=" );
+ _printer.printText( _format.getEncoding());
+ _printer.printText( '"' );
+ }
}
- if ( htmlName != null && ( rawName.equalsIgnoreCase( "HEAD" )))
- {
- _printer.printText( '>' );
- // Insert Meta tag here
- _printer.breakLine();
- _printer.printText( '<' );
- _printer.printText( "META" );
- _printer.printText( " http-equiv=\"Content-Type\"" );
- _printer.printText( " content=\"text/html;");
- // _printer.printText( _format.getMediaType() +'"' );
- _printer.printText( " charset=");
- _printer.printText( _format.getEncoding() +'"' );
- }
}
1.5 +56 -27
xml-xalan/java/src/org/apache/xml/serialize/transition/IndentPrinter.java
Index: IndentPrinter.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serialize/transition/IndentPrinter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- IndentPrinter.java 2000/10/17 19:26:18 1.4
+++ IndentPrinter.java 2000/10/18 04:36:47 1.5
@@ -69,29 +69,13 @@
* Extends [EMAIL PROTECTED] Printer} and adds support for indentation and
line
* wrapping.
*
- * @version $Revision: 1.4 $ $Date: 2000/10/17 19:26:18 $
+ * @version $Revision: 1.5 $ $Date: 2000/10/18 04:36:47 $
* @author <a href="mailto:[EMAIL PROTECTED]">Assaf Arkin</a>
*/
class IndentPrinter
extends Printer
{
-
- /**
- * Holds the currently accumulating text line. This buffer will
constantly
- * be reused by deleting its contents instead of reallocating it.
- */
- private StringBuffer _line;
-
-
- /**
- * Holds the currently accumulating text that follows [EMAIL PROTECTED]
#_line}.
- * When the end of the part is identified by a call to [EMAIL PROTECTED]
#printSpace}
- * or [EMAIL PROTECTED] #breakLine}, this part is added to the
accumulated line.
- */
- private StringBuffer _text;
-
-
/**
* Counts how many white spaces come between the accumulated line and the
* current accumulated text. Multiple spaces at the end of the a line
@@ -129,13 +113,58 @@
_spacechars[i] = ' ';
}
}
+
+ /**
+ * Holds the currently accumulating text line. This buffer will
constantly
+ * be reused by deleting its contents instead of reallocating it.
+ */
+ private FastStringBuffer _line;
+ // private StringBuffer _line;
+ /**
+ * Holds the currently accumulating text that follows [EMAIL PROTECTED]
#_line}.
+ * When the end of the part is identified by a call to [EMAIL PROTECTED]
#printSpace}
+ * or [EMAIL PROTECTED] #breakLine}, this part is added to the
accumulated line.
+ */
+ private FastStringBuffer _text;
+ // private StringBuffer _text;
+
+ private final void resetTextBuf()
+ {
+ _text.reset();
+ // _text = new StringBuffer(100);
+ }
+
+ private final void resetLineBuf()
+ {
+ _line.reset();
+ // _line = new StringBuffer(1024);
+ }
+
+ /**
+ * The point at which the IndentPrinter should try to
+ * flush the accumulated text into the printer.
+ */
+ public static int TRY_TO_FLUSH_AT = 1024;
+
+ private final void flushLineBuf()
+ throws IOException
+ {
+ _writer.write(_line.m_map, 0, _line.m_firstFree);
+ // String s = _line.toString();
+ // _writer.write(s);
+ resetLineBuf();
+ }
+
+
IndentPrinter( Writer writer, OutputFormat format)
{
super( writer, format );
// Initialize everything for a first/second run.
- _line = new StringBuffer( 80 );
- _text = new StringBuffer( 20 );
+ _line = new FastStringBuffer( 2048 );
+ _text = new FastStringBuffer( 2048 );
+ // _line = new StringBuffer( 1024 );
+ // _text = new StringBuffer( 100 );
_spaces = 0;
_thisIndent = _nextIndent = 0;
}
@@ -178,7 +207,7 @@
// state, can no longer re-enter it.
if ( _dtdWriter == null ) {
_line.append( _text );
- _text = new StringBuffer( 20 );
+ resetTextBuf();
flushLine( false );
_dtdWriter = new StringWriter();
_docWriter = _writer;
@@ -197,7 +226,7 @@
// Only works if we're going out of DTD mode.
if ( _writer == _dtdWriter ) {
_line.append( _text );
- _text = new StringBuffer( 20 );
+ resetTextBuf();
flushLine( false );
_writer = _docWriter;
return _dtdWriter.toString();
@@ -296,7 +325,10 @@
_spaces = 0;
}
_line.append( _text );
- _text.setLength(0);
+ resetTextBuf();
+
+ if(_line.length() > TRY_TO_FLUSH_AT)
+ flushLine( false );
}
// Starting a new word: accumulate the text between the line
// and this new word; not a new word: just add another space.
@@ -328,7 +360,7 @@
_spaces = 0;
}
_line.append( _text );
- _text = new StringBuffer( 20 );
+ resetTextBuf();
}
flushLine( preserveSpace );
try {
@@ -375,10 +407,7 @@
// they are simply stripped and replaced with a single line
// separator.
_spaces = 0;
- String s = _line.toString();
- _writer.write( s );
-
- _line.setLength(0);
+ flushLineBuf();
} catch ( IOException except ) {
// We don't throw an exception, but hold it
// until the end of the document.
1.1
xml-xalan/java/src/org/apache/xml/serialize/transition/FastStringBuffer.java
Index: FastStringBuffer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xml.serialize.transition;
/**
* Bare-bones, unsafe, fast string buffer.
*/
public class FastStringBuffer
{
public int m_blocksize;
public char m_map[]; // don't hold on to a reference!
public int m_firstFree = 0;
public int m_mapSize;
/**
* Construct a IntVector, using the given block size.
*/
public FastStringBuffer(int blocksize)
{
m_blocksize = blocksize;
m_mapSize = blocksize;
m_map = new char[blocksize];
}
/**
* Get the length of the list.
*/
public final int size()
{
return m_firstFree;
}
public final int length()
{
return m_firstFree;
}
public final void reset()
{
m_firstFree = 0;
}
public final void setLength(int l)
{
m_firstFree = l;
}
private final void ensureSize(int newSize)
{
if((m_firstFree+newSize) >= m_mapSize)
{
if(m_blocksize > newSize)
m_mapSize+=m_blocksize;
else
m_mapSize+=(newSize+m_blocksize);
char newMap[] = new char[m_mapSize];
System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
m_map = newMap;
}
}
/**
* Append a int onto the vector.
*/
public final void append(char value)
{
int ff = m_firstFree;
if((ff+1) >= m_mapSize)
{
m_mapSize+=m_blocksize+1;
char newMap[] = new char[m_mapSize];
System.arraycopy(m_map, 0, newMap, 0, ff);
m_map = newMap;
}
m_map[ff] = value;
m_firstFree = ff+1;
}
/**
* Append a int onto the vector.
*/
public final void append(String value)
{
int len = value.length();
ensureSize(len);
value.getChars(0, len, m_map, m_firstFree);
m_firstFree+=len;
}
/**
* Append a int onto the vector.
*/
public final void append(StringBuffer value)
{
int len = value.length();
ensureSize(len);
value.getChars(0, len, m_map, m_firstFree);
m_firstFree+=len;
}
public final void append( char[] chars, int start, int length )
{
ensureSize(length);
System.arraycopy(chars, start, m_map, m_firstFree, length);
m_firstFree+=length;
}
public final void append( FastStringBuffer value )
{
int length = value.m_firstFree;
ensureSize(length);
System.arraycopy(value.m_map, 0, m_map, m_firstFree, length);
m_firstFree+=length;
}
}
1.7 +3 -2 xml-xalan/java/src/org/apache/xpath/DOMHelper.java
Index: DOMHelper.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/DOMHelper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DOMHelper.java 2000/10/17 19:29:51 1.6
+++ DOMHelper.java 2000/10/18 04:36:47 1.7
@@ -7,6 +7,7 @@
import org.apache.xalan.utils.NSInfo;
import org.apache.xalan.utils.QName;
import org.apache.xalan.utils.StringBufferPool;
+import org.apache.xalan.utils.FastStringBuffer;
import org.apache.xalan.res.XSLMessages;
import org.apache.xpath.res.XPATHErrorResources;
@@ -757,7 +758,7 @@
*/
public static String getNodeData(Node node)
{
- StringBuffer buf = StringBufferPool.get();
+ FastStringBuffer buf = StringBufferPool.get();
String s;
try
{
@@ -778,7 +779,7 @@
* or declare victory when I review the entire
* whitespace handling).
*/
- public static void getNodeData(Node node, StringBuffer buf)
+ public static void getNodeData(Node node, FastStringBuffer buf)
{
// String data = null;
1.8 +18 -0 xml-xalan/java/src/org/apache/xpath/XPathContext.java
Index: XPathContext.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathContext.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XPathContext.java 2000/10/17 19:32:00 1.7
+++ XPathContext.java 2000/10/18 04:36:47 1.8
@@ -394,6 +394,24 @@
{
return m_currentNodes.peepOrNull();
}
+
+ /**
+ * Set the current context node.
+ */
+ public final void pushCurrentNodeAndExpression(Node cn, Node en)
+ {
+ m_currentNodes.push(cn);
+ m_currentExpressionNodes.push(en);
+ }
+
+ /**
+ * Set the current context node.
+ */
+ public final void popCurrentNodeAndExpression()
+ {
+ m_currentNodes.pop();
+ m_currentExpressionNodes.pop();
+ }
/**
* Set the current context node.