You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2003/05/13 20:05:17 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/serializer ToXMLSAXHandler.java ToHTMLStream.java SerializerBase.java ToStream.java
minchau 2003/05/13 11:05:17
Modified: java/src/org/apache/xml/serializer ToXMLSAXHandler.java
ToHTMLStream.java SerializerBase.java ToStream.java
Log:
See bugzilla # 19900 for a laundry list of small performance
enhancements.
PR: bugzilla 19900
Submitted by: Brian Minchau
Reviewed by: Henry Zongaro
Revision Changes Path
1.4 +2 -1 xml-xalan/java/src/org/apache/xml/serializer/ToXMLSAXHandler.java
Index: ToXMLSAXHandler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToXMLSAXHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ToXMLSAXHandler.java 9 May 2003 18:47:56 -0000 1.3
+++ ToXMLSAXHandler.java 13 May 2003 18:05:16 -0000 1.4
@@ -309,7 +309,8 @@
m_currentElemDepth--;
m_startTagOpen = false;
// m_disableOutputEscapingStates.pop();
- m_cdataSectionStates.pop();
+ if (m_cdataSectionElements != null)
+ m_cdataSectionStates.pop();
m_elementURI = null;
m_elementLocalName = null;
}
1.6 +61 -57 xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java
Index: ToHTMLStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ToHTMLStream.java 9 May 2003 18:47:56 -0000 1.5
+++ ToHTMLStream.java 13 May 2003 18:05:16 -0000 1.6
@@ -615,7 +615,7 @@
}
/** The name of the current element. */
- private String m_currentElementName = null;
+// private String m_currentElementName = null;
/**
* Receive notification of the beginning of a document.
@@ -727,9 +727,15 @@
// System.out.println("SerializerToHTML#startElement("+namespaceURI+", "+localName+", "+name+", ...);");
if (m_cdataTagOpen)
- closeCDATA();
+ {
+ closeCDATA();
+ m_cdataTagOpen = false;
+ }
else if (m_needToCallStartDocument)
- startDocumentInternal();
+ {
+ startDocumentInternal();
+ m_needToCallStartDocument = false;
+ }
// if (m_needToOutputDocTypeDecl
// && ( (null != getDoctypeSystem()) || (null!= getDoctypePublic())))
@@ -757,11 +763,7 @@
}
ElemDesc elemDesc = getElemDesc(name);
- // remember for later
- m_elementLocalName = localName;
- m_elementURI = namespaceURI;
- m_elementName = name;
- m_elementDesc = elemDesc;
+
// ElemDesc parentElemDesc = getElemDesc(m_currentElementName);
boolean isBlockElement = elemDesc.is(ElemDesc.BLOCK);
@@ -772,7 +774,7 @@
m_ispreserve = false;
else if (
m_doIndent
- && (null != m_currentElementName)
+ && (null != m_elementName)
&& (!m_inBlockElem || isBlockElement) /* && !isWhiteSpaceSensitive */
)
{
@@ -782,11 +784,15 @@
}
m_inBlockElem = !isBlockElement;
+
+ // remember for later
+ m_elementLocalName = localName;
+ m_elementURI = namespaceURI;
+ m_elementName = name;
+ m_elementDesc = elemDesc;
m_isRawStack.push(elemDesc.is(ElemDesc.RAW));
- m_currentElementName = name;
-
// m_parents.push(m_currentElementName);
m_writer.write('<');
m_writer.write(name);
@@ -803,7 +809,10 @@
if (isHeadElement)
{
if (m_startTagOpen)
+ {
closeStartTag();
+ m_startTagOpen = false;
+ }
if (!m_omitMetaTag)
{
@@ -896,18 +905,23 @@
m_writer.write(name);
m_writer.write('>');
- m_currentElementName = name;
+ m_elementName = name;
- m_cdataSectionStates.pop();
- if (!m_preserves.isEmpty())
+ if (m_cdataSectionElements != null)
+ m_cdataSectionStates.pop();
+ if (m_doIndent && !m_preserves.isEmpty())
m_preserves.pop();
}
else
{
+ if (m_tracer != null)
+ super.fireStartElem(m_elementName);
/* process any attributes gathered after the
* startElement(String) call
*/
- processAttributes();
+ int nAttrs = m_attributes.getLength();
+ if (nAttrs > 0)
+ processAttributes(nAttrs);
if (!elemDesc.is(ElemDesc.EMPTY))
{
m_writer.write('>');
@@ -1435,9 +1449,9 @@
throws org.xml.sax.SAXException
{
- if ((null != m_currentElementName)
- && (m_currentElementName.equalsIgnoreCase("SCRIPT")
- || m_currentElementName.equalsIgnoreCase("STYLE")))
+ if ((null != m_elementName)
+ && (m_elementName.equalsIgnoreCase("SCRIPT")
+ || m_elementName.equalsIgnoreCase("STYLE")))
{
try
{
@@ -1576,21 +1590,14 @@
* calls for an element from calls to
* attribute(String name, String value)
*
- * @param attribSAX official attributes from a SAX call to startElement
+ * @param nAttrs the number of attributes in m_attributes
+ * to be processed
*
* @throws org.xml.sax.SAXException
*/
- public void processAttributes()
+ public void processAttributes(int nAttrs)
throws IOException,SAXException
{
-
- // finish processing attributes, time to fire off the start element event
- if (m_tracer != null)
- super.fireStartElem(m_elementName);
-
- int nAttrs = 0;
- if ((nAttrs = m_attributes.getLength()) > 0)
- {
/*
* process the collected attributes
*/
@@ -1601,15 +1608,7 @@
m_attributes.getValue(i),
m_elementDesc);
}
-
-
-
-
-
-
m_attributes.clear();
-
- }
}
/**
@@ -1620,31 +1619,36 @@
*/
protected void closeStartTag() throws SAXException
{
- if (m_startTagOpen)
- {
- try
- {
-
- processAttributes();
-
- m_writer.write('>');
-
- /* whether Xalan or XSLTC, we have the prefix mappings now, so
- * lets determine if the current element is specified in the cdata-
- * section-elements list.
- */
- pushCdataSectionState();
+ try
+ {
- m_isprevtext = false;
- m_preserves.push(m_ispreserve);
- m_startTagOpen = false;
+ // finish processing attributes, time to fire off the start element event
+ if (m_tracer != null)
+ super.fireStartElem(m_elementName);
- }
- catch(IOException e)
+ int nAttrs = m_attributes.getLength();
+ if (nAttrs>0)
+ processAttributes(nAttrs);
+
+ m_writer.write('>');
+
+ /* whether Xalan or XSLTC, we have the prefix mappings now, so
+ * lets determine if the current element is specified in the cdata-
+ * section-elements list.
+ */
+ if (m_cdataSectionElements != null)
+ pushCdataSectionState();
+ if (m_doIndent)
{
- throw new SAXException(e);
+ m_isprevtext = false;
+ m_preserves.push(m_ispreserve);
}
- }
+
+ }
+ catch(IOException e)
+ {
+ throw new SAXException(e);
+ }
}
/**
* Initialize the serializer with the specified output stream and output
1.5 +3 -8 xml-xalan/java/src/org/apache/xml/serializer/SerializerBase.java
Index: SerializerBase.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/SerializerBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SerializerBase.java 9 May 2003 18:47:56 -0000 1.4
+++ SerializerBase.java 13 May 2003 18:05:16 -0000 1.5
@@ -791,8 +791,8 @@
/**
* Push a boolean state based on if the name of the element
- * is found in the list of qnames. A state is always pushed,
- * one way or the other.
+ * is found in the list of qnames. A state is only pushed if
+ * there were some cdata-section-names were specified.
*
* @param namespaceURI Should be a non-null reference to the namespace URL
* of the element that owns the state, or empty string.
@@ -841,13 +841,8 @@
break;
}
}
+ m_cdataSectionStates.push(b);
}
- else
- {
- b = m_cdataSectionStates.peekOrFalse();
- }
-
- m_cdataSectionStates.push(b);
}
/**
1.6 +43 -26 xml-xalan/java/src/org/apache/xml/serializer/ToStream.java
Index: ToStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToStream.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ToStream.java 9 May 2003 18:47:56 -0000 1.5
+++ ToStream.java 13 May 2003 18:05:16 -0000 1.6
@@ -123,18 +123,31 @@
/**
* Stack to keep track of whether or not we need to
* preserve whitespace.
+ *
+ * Used to push/pop values used for the field m_ispreserve, but
+ * m_ispreserve is only relevant if m_doIndent is true.
+ * If m_doIndent is false this field has no impact.
+ *
*/
protected BoolStack m_preserves = new BoolStack();
/**
* State flag to tell if preservation of whitespace
- * is important.
+ * is important.
+ *
+ * Used only in shouldIndent() but only if m_doIndent is true.
+ * If m_doIndent is false this flag has no impact.
+ *
*/
protected boolean m_ispreserve = false;
/**
* State flag that tells if the previous node processed
* was text, so we can tell if we should preserve whitespace.
+ *
+ * Used in endDocument() and shouldIndent() but
+ * only if m_doIndent is true.
+ * If m_doIndent is false this flag has no impact.
*/
protected boolean m_isprevtext = false;
@@ -191,6 +204,9 @@
/**
* Flag to signal that a newline should be added.
+ *
+ * Used only in indent() which is called only if m_doIndent is true.
+ * If m_doIndent is false this flag has no impact.
*/
boolean m_startNewLine;
@@ -1442,7 +1458,11 @@
}
if (m_startTagOpen)
+ {
closeStartTag();
+ m_startTagOpen = false;
+ }
+
int startClean = start;
int lengthClean = 0;
@@ -1830,21 +1850,12 @@
* Process the colleced attributes from SAX- like calls for an element from
* calls to addattibute(String name, String value)
*
- *
+ * @param nAttrs the number of attributes in m_attributes to be processed
* @throws org.xml.sax.SAXException
*/
- public void processAttributes() throws IOException, SAXException
+ public void processAttributes(int nAttrs) throws IOException, SAXException
{
- // finish processing attributes, time to fire off the start element event
- if (m_tracer != null)
- super.fireStartElem(m_elementName);
-
- int nAttrs = 0;
- // if passed real SAX attributes, then process only them
-
- if ((nAttrs = m_attributes.getLength()) > 0)
- {
/* real SAX attributes are not passed in, so process the
* attributes that were collected after the startElement call.
* _attribVector is a "cheap" list for Stream serializer output
@@ -1869,8 +1880,6 @@
* .removeAllElements() is used as it is from JDK 1.1.8
*/
m_attributes.clear();
-
- }
}
/**
@@ -1947,10 +1956,11 @@
{
if (m_startTagOpen)
{
- /* The start tag is still open and we have hit
- * endElement, so close it down
- */
- processAttributes();
+ if (m_tracer != null)
+ super.fireStartElem(m_elementName);
+ int nAttrs = m_attributes.getLength();
+ if (nAttrs > 0)
+ processAttributes(nAttrs);
if (m_spaceBeforeClose)
m_writer.write(" />");
else
@@ -1972,7 +1982,8 @@
m_writer.write('/');
m_writer.write(name);
m_writer.write('>');
- m_cdataSectionStates.pop();
+ if (m_cdataSectionElements != null)
+ m_cdataSectionStates.pop();
}
}
catch (IOException e)
@@ -1980,7 +1991,7 @@
throw new SAXException(e);
}
- if (!m_startTagOpen)
+ if (!m_startTagOpen && m_doIndent)
{
m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop();
}
@@ -2324,7 +2335,11 @@
try
{
- processAttributes();
+ if (m_tracer != null)
+ super.fireStartElem(m_elementName);
+ int nAttrs = m_attributes.getLength();
+ if (nAttrs > 0)
+ processAttributes(nAttrs);
m_writer.write('>');
}
catch (IOException e)
@@ -2336,12 +2351,14 @@
* lets determine if the current element is specified in the cdata-
* section-elements list.
*/
- pushCdataSectionState();
-
- m_isprevtext = false;
- m_preserves.push(m_ispreserve);
- m_startTagOpen = false;
+ if (m_cdataSectionElements != null)
+ pushCdataSectionState();
+ if (m_doIndent)
+ {
+ m_isprevtext = false;
+ m_preserves.push(m_ispreserve);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org