dbertoni 01/07/22 18:39:46
Modified: c/src/XSLT ElemCopy.cpp ElemCopyOf.cpp
ElemTemplateElement.cpp
StylesheetExecutionContext.hpp
StylesheetExecutionContextDefault.cpp
StylesheetExecutionContextDefault.hpp
XSLTEngineImpl.cpp XSLTEngineImpl.hpp
Log:
More efficient result tree processing.
Revision Changes Path
1.15 +6 -10 xml-xalan/c/src/XSLT/ElemCopy.cpp
Index: ElemCopy.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemCopy.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ElemCopy.cpp 2001/07/12 05:05:37 1.14
+++ ElemCopy.cpp 2001/07/23 01:39:45 1.15
@@ -116,35 +116,32 @@
void
-ElemCopy::execute(StylesheetExecutionContext&
executionContext) const
+ElemCopy::execute(StylesheetExecutionContext& executionContext) const
{
- XalanNode* sourceNode = executionContext.getCurrentNode();
+ XalanNode* const sourceNode = executionContext.getCurrentNode();
assert(sourceNode != 0);
- const XalanNode::NodeType nodeType =
executionContext.getCurrentNode()->getNodeType();
+ const XalanNode::NodeType nodeType = sourceNode->getNodeType();
if(XalanNode::DOCUMENT_NODE != nodeType)
{
executionContext.cloneToResultTree(
*sourceNode,
+ nodeType,
false,
false,
false);
if(XalanNode::ELEMENT_NODE == nodeType)
{
- assert(sourceNode != 0);
-
ElemUse::execute(executionContext);
executionContext.copyNamespaceAttributes(*sourceNode);
executeChildren(executionContext);
-
- const XalanDOMString& s =
DOMServices::getNameOfNode(*sourceNode);
- executionContext.endElement(c_wstr(s));
+
executionContext.endElement(c_wstr(sourceNode->getNodeName()));
}
else
{
@@ -163,8 +160,7 @@
*this));
}
- ElemUse::execute(
- executionContext);
+ ElemUse::execute(executionContext);
executeChildren(executionContext);
}
1.22 +14 -4 xml-xalan/c/src/XSLT/ElemCopyOf.cpp
Index: ElemCopyOf.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemCopyOf.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ElemCopyOf.cpp 2001/07/22 04:31:54 1.21
+++ ElemCopyOf.cpp 2001/07/23 01:39:45 1.22
@@ -143,17 +143,19 @@
StylesheetExecutionContext&
executionContext,
XalanNode&
theNode) const
{
- XalanNode* pos = &theNode;
+ XalanNode* pos = &theNode;
+ XalanNode::NodeType posNodeType = pos->getNodeType();
while(pos != 0)
{
- if(pos->getNodeType() != XalanNode::ATTRIBUTE_NODE)
+ if(posNodeType != XalanNode::ATTRIBUTE_NODE)
{
executionContext.flushPending();
}
executionContext.cloneToResultTree(
*pos,
+ posNodeType,
false,
false,
true);
@@ -162,7 +164,7 @@
while(nextNode == 0)
{
- if(XalanNode::ELEMENT_NODE == pos->getNodeType())
+ if(XalanNode::ELEMENT_NODE == posNodeType)
{
executionContext.endElement(c_wstr(pos->getNodeName()));
}
@@ -175,10 +177,13 @@
if(nextNode == 0)
{
pos = pos->getParentNode();
+ assert(pos != 0);
+ posNodeType = pos->getNodeType();
+
if(&theNode == pos)
{
- if(XalanNode::ELEMENT_NODE ==
pos->getNodeType())
+ if(XalanNode::ELEMENT_NODE ==
posNodeType)
{
executionContext.endElement(c_wstr(pos->getNodeName()));
}
@@ -190,6 +195,11 @@
}
pos = nextNode;
+
+ if (pos != 0)
+ {
+ posNodeType = pos->getNodeType();
+ }
}
}
1.64 +9 -14 xml-xalan/c/src/XSLT/ElemTemplateElement.cpp
Index: ElemTemplateElement.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- ElemTemplateElement.cpp 2001/07/18 04:33:15 1.63
+++ ElemTemplateElement.cpp 2001/07/23 01:39:45 1.64
@@ -833,6 +833,8 @@
const ElemTemplateElement* theTemplate,
XalanNode*
child) const
{
+ assert(child != 0);
+
const XalanNode::NodeType nodeType = child->getNodeType();
if(0 == theTemplate)
@@ -884,24 +886,17 @@
{
case XalanNode::CDATA_SECTION_NODE:
case XalanNode::TEXT_NODE:
- executionContext.cloneToResultTree(
- *child, false, false,
false);
+ executionContext.cloneToResultTree(*child,
nodeType, false, false, false);
break;
case XalanNode::ATTRIBUTE_NODE:
{
- const XalanAttr* const attr =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanAttr*)child;
-#else
- static_cast<const
XalanAttr*>(child);
-#endif
-
- const XalanDOMString& val =
attr->getValue();
-
-
executionContext.characters(toCharArray(val),
-
0,
-
length(val));
+ const XalanDOMString& val =
child->getNodeValue();
+
+ executionContext.characters(
+ toCharArray(val),
+ 0,
+ length(val));
}
break;
1.61 +6 -4 xml-xalan/c/src/XSLT/StylesheetExecutionContext.hpp
Index: StylesheetExecutionContext.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContext.hpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- StylesheetExecutionContext.hpp 2001/07/18 04:33:15 1.60
+++ StylesheetExecutionContext.hpp 2001/07/23 01:39:45 1.61
@@ -994,16 +994,18 @@
* Clone an element with or without children.
*
* @param node node to clone
+ * @param nodeType the type of the node
* @param isLiteral true if a literal element
* @param overrideStrip false if white space stripping should
be done
* @param shouldCloneAttributes true if attributes should be cloned
*/
virtual void
cloneToResultTree(
- XalanNode& node,
- bool isLiteral,
- bool overrideStrip,
- bool shouldCloneAttributes) = 0;
+ XalanNode& node,
+ XalanNode::NodeType nodeType,
+ bool isLiteral,
+ bool overrideStrip,
+ bool
shouldCloneAttributes) = 0;
/**
* Create an XObject that represents a Result tree fragment.
1.71 +11 -8
xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.cpp
Index: StylesheetExecutionContextDefault.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- StylesheetExecutionContextDefault.cpp 2001/07/18 04:33:15 1.70
+++ StylesheetExecutionContextDefault.cpp 2001/07/23 01:39:45 1.71
@@ -882,17 +882,20 @@
void
StylesheetExecutionContextDefault::cloneToResultTree(
- XalanNode& node,
- bool isLiteral,
- bool overrideStrip,
- bool shouldCloneAttributes)
+ XalanNode& node,
+ XalanNode::NodeType nodeType,
+ bool isLiteral,
+ bool overrideStrip,
+ bool
shouldCloneAttributes)
{
assert(m_xsltProcessor != 0);
- m_xsltProcessor->cloneToResultTree(node,
-
isLiteral,
-
overrideStrip,
-
shouldCloneAttributes);
+ m_xsltProcessor->cloneToResultTree(
+ node,
+ nodeType,
+ isLiteral,
+ overrideStrip,
+ shouldCloneAttributes);
}
1.64 +5 -4
xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.hpp
Index: StylesheetExecutionContextDefault.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.hpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- StylesheetExecutionContextDefault.hpp 2001/07/18 04:33:15 1.63
+++ StylesheetExecutionContextDefault.hpp 2001/07/23 01:39:45 1.64
@@ -476,10 +476,11 @@
virtual void
cloneToResultTree(
- XalanNode& node,
- bool isLiteral,
- bool overrideStrip,
- bool shouldCloneAttributes);
+ XalanNode& node,
+ XalanNode::NodeType nodeType,
+ bool isLiteral,
+ bool overrideStrip,
+ bool
shouldCloneAttributes);
virtual const XObjectPtr
createXResultTreeFrag(
1.109 +90 -130 xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp
Index: XSLTEngineImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- XSLTEngineImpl.cpp 2001/07/18 04:33:15 1.108
+++ XSLTEngineImpl.cpp 2001/07/23 01:39:45 1.109
@@ -61,10 +61,7 @@
#include "XSLTEngineImpl.hpp"
-#include <memory>
-
-
#include <sax/DocumentHandler.hpp>
#include <sax/EntityResolver.hpp>
#include <sax/Locator.hpp>
@@ -464,8 +461,6 @@
const XSLTInputSource input(c_wstr(xsldocURLString));
return processStylesheet(input, constructionContext);
-
- return 0;
}
@@ -972,7 +967,7 @@
case XObject::eTypeNodeSet:
{
- XalanDOMString s;
+// XalanDOMString s;
const NodeRefListBase& nl = value.nodeset();
@@ -981,19 +976,23 @@
for(unsigned int i = 0; i < nChildren; i++)
{
XalanNode* pos =
nl.item(i);
+ assert(pos != 0);
+
XalanNode* const top = pos;
while(0 != pos)
{
flushPending();
+
+ XalanNode::NodeType
posNodeType = pos->getNodeType();
- cloneToResultTree(*pos, false, false,
true);
+ cloneToResultTree(*pos, posNodeType,
false, false, true);
XalanNode* nextNode =
pos->getFirstChild();
while(0 == nextNode)
{
- if(XalanNode::ELEMENT_NODE ==
pos->getNodeType())
+ if(XalanNode::ELEMENT_NODE ==
posNodeType)
{
endElement(c_wstr(pos->getNodeName()));
}
@@ -1006,10 +1005,13 @@
if(0 == nextNode)
{
pos =
pos->getParentNode();
+ assert(pos != 0);
+ posNodeType =
pos->getNodeType();
+
if(top == pos)
{
-
if(XalanNode::ELEMENT_NODE == pos->getNodeType())
+
if(XalanNode::ELEMENT_NODE == posNodeType)
{
endElement(c_wstr(pos->getNodeName()));
}
@@ -1021,6 +1023,11 @@
}
pos = nextNode;
+
+ if (pos != 0)
+ {
+ posNodeType =
pos->getNodeType();
+ }
}
}
}
@@ -2145,14 +2152,15 @@
void
XSLTEngineImpl::cloneToResultTree(
- XalanNode& node,
- bool isLiteral,
- bool overrideStrip,
- bool shouldCloneAttributes)
+ XalanNode& node,
+ XalanNode::NodeType nodeType,
+ bool isLiteral,
+ bool overrideStrip,
+ bool
shouldCloneAttributes)
{
- const XalanNode::NodeType theType = node.getNodeType();
+ assert(nodeType == node.getNodeType());
- switch(theType)
+ switch(nodeType)
{
case XalanNode::TEXT_NODE:
{
@@ -2173,7 +2181,9 @@
static_cast<const XalanText&>(node);
#endif
- if(stripWhiteSpace == false ||
tx.isIgnorableWhitespace() == false)
+ const bool isIgnorableWhitespace =
tx.isIgnorableWhitespace();
+
+ if(stripWhiteSpace == false || isIgnorableWhitespace ==
false)
{
assert(tx.getParentNode() == 0 ||
tx.getParentNode()->getNodeType() !=
XalanNode::DOCUMENT_NODE);
@@ -2182,17 +2192,7 @@
if(0 != length(data))
{
- // TODO: Hack around the issue of
comments next to literals.
- // This would be, when a comment is
present, the whitespace
- // after the comment must be added to
the literal. The
- // parser should do this, but XML4J
doesn't seem to.
- // <foo>some lit text
- // <!-- comment -->
- // </foo>
- // Loop through next siblings while
they are comments, then,
- // if the node after that is a
ignorable text node, append
- // it to the text node just added.
- if(tx.isIgnorableWhitespace())
+ if(isIgnorableWhitespace == true)
{
ignorableWhitespace(toCharArray(data), length(data));
}
@@ -2206,98 +2206,54 @@
break;
case XalanNode::ELEMENT_NODE:
- {
- startElement(c_wstr(DOMServices::getNameOfNode(node)));
+ startElement(c_wstr(node.getNodeName()));
- if(shouldCloneAttributes == true)
- {
- copyAttributesToAttList(&node,
-
m_stylesheetRoot,
-#if defined(XALAN_OLD_STYLE_CASTS)
-
(const XalanElement&)node,
-#else
-
static_cast<const XalanElement&>(node),
-#endif
-
getPendingAttributesImpl());
+ if(shouldCloneAttributes == true)
+ {
+ copyAttributesToAttList(
+
m_stylesheetRoot,
+ node,
+
getPendingAttributesImpl());
- copyNamespaceAttributes(node);
- }
+ copyNamespaceAttributes(node);
}
break;
case XalanNode::CDATA_SECTION_NODE:
{
- const XalanCDATASection& theCDATA =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanCDATASection&)node;
-#else
- static_cast<const XalanCDATASection&>(node);
-#endif
-
- const XalanDOMString& data = theCDATA.getData();
+ const XalanDOMString& data = node.getNodeValue();
cdata(toCharArray(data), 0, length(data));
}
break;
case XalanNode::ATTRIBUTE_NODE:
- {
- const XalanAttr& attr =
+ addResultAttribute(
+ getPendingAttributesImpl(),
#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanAttr&)node;
+ DOMServices::getNameOfNode((const
XalanAttr&)node),
#else
- static_cast<const XalanAttr&>(node);
+ DOMServices::getNameOfNode(static_cast<const
XalanAttr&>(node)),
#endif
- addResultAttribute(getPendingAttributesImpl(),
-
DOMServices::getNameOfNode(attr),
- attr.getValue());
- }
+ node.getNodeValue());
break;
case XalanNode::COMMENT_NODE:
- {
- const XalanComment& theComment =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanComment&)node;
-#else
- static_cast<const XalanComment&>(node);
-#endif
-
- const XalanDOMString& theData = theComment.getData();
-
- comment(c_wstr(theData));
- }
+ comment(c_wstr(node.getNodeValue()));
break;
case XalanNode::DOCUMENT_FRAGMENT_NODE:
- {
- error("No clone of a document fragment!");
- }
+ error("No clone of a document fragment!");
break;
case XalanNode::ENTITY_REFERENCE_NODE:
- {
- const XalanDOMString & theName = node.getNodeName();
-
- entityReference(c_wstr(theName));
- }
+ entityReference(c_wstr(node.getNodeName()));
break;
case XalanNode::PROCESSING_INSTRUCTION_NODE:
- {
- const XalanProcessingInstruction& pi =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanProcessingInstruction&)node;
-#else
- static_cast<const
XalanProcessingInstruction&>(node);
-#endif
-
- const XalanDOMString& theTarget = pi.getTarget();
- const XalanDOMString& theData = pi.getData();
-
- processingInstruction(c_wstr(theTarget),
-
c_wstr(theData));
- }
+ processingInstruction(
+ c_wstr(node.getNodeName()),
+ c_wstr(node.getNodeValue()));
break;
// Can't really do this, but we won't throw an error so that copy-of
will
@@ -2329,20 +2285,24 @@
for(unsigned int i = 0; i < nChildren; i++)
{
- XalanNode* pos = nl->item(i);
- XalanNode* const top = pos;
+ XalanNode* pos = nl->item(i);
+ assert(pos != 0);
+
+ XalanNode::NodeType posNodeType =
pos->getNodeType();
+
+ XalanNode* const top = pos;
while(0 != pos)
{
flushPending();
- cloneToResultTree(*pos, false, false, true);
+ cloneToResultTree(*pos, posNodeType, false, false,
true);
XalanNode* nextNode = pos->getFirstChild();
while(0 == nextNode)
{
- if(XalanNode::ELEMENT_NODE ==
pos->getNodeType())
+ if(XalanNode::ELEMENT_NODE == posNodeType)
{
endElement(c_wstr(pos->getNodeName()));
}
@@ -2356,23 +2316,39 @@
{
pos = pos->getParentNode();
- if(top == pos || 0 == pos)
+ if(0 == pos)
{
- if (0 != pos)
+ nextNode = 0;
+
+ break;
+ }
+ else
+ {
+ assert(0 != pos);
+
+ posNodeType =
pos->getNodeType();
+
+ if(top == pos)
{
-
if(XalanNode::ELEMENT_NODE == pos->getNodeType())
+
if(XalanNode::ELEMENT_NODE == posNodeType)
{
endElement(c_wstr(pos->getNodeName()));
}
- }
- nextNode = 0;
- break;
+ nextNode = 0;
+
+ break;
+ }
}
}
}
pos = nextNode;
+
+ if (pos != 0)
+ {
+ posNodeType = pos->getNodeType();
+ }
}
}
}
@@ -2655,12 +2631,10 @@
void
XSLTEngineImpl::copyNamespaceAttributes(const XalanNode& src)
{
- int type;
-
const XalanNode* parent = &src;
while (parent != 0 &&
- (type = parent->getNodeType()) == XalanNode::ELEMENT_NODE)
+ parent->getNodeType() == XalanNode::ELEMENT_NODE)
{
const XalanNamedNodeMap* const nnm =
parent->getAttributes();
@@ -2775,18 +2749,12 @@
-void
+inline void
XSLTEngineImpl::copyAttributeToTarget(
- const XalanAttr& attr,
- XalanNode* /* contextNode
*/,
- const Stylesheet* /* stylesheetTree */,
- AttributeListImpl& attrList,
- const XalanElement& /* namespaceContext */)
+ const XalanDOMString& attrName,
+ const XalanDOMString& attrValue,
+ AttributeListImpl& attrList)
{
- const XalanDOMString& attrName = attr.getName();
-
- const XalanDOMString& attrValue = attr.getValue();
-
// TODO: Find out about empty attribute template expression handling.
if(0 != length(attrValue))
{
@@ -2798,16 +2766,15 @@
void
XSLTEngineImpl::copyAttributesToAttList(
- XalanNode* contextNode,
- const Stylesheet* stylesheetTree,
- const XalanElement& templateChild,
- AttributeListImpl& attList)
+ const Stylesheet* stylesheetTree,
+ const XalanNode& node,
+ AttributeListImpl& attList)
{
assert(m_stylesheetRoot != 0);
assert(stylesheetTree != 0);
const XalanNamedNodeMap* const attributes =
- templateChild.getAttributes();
+ node.getAttributes();
if (attributes != 0)
{
@@ -2815,20 +2782,13 @@
for(unsigned int i = 0; i < nAttributes; ++i)
{
- const XalanAttr* const attr =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanAttr*)attributes->item(i);
-#else
- static_cast<const
XalanAttr*>(attributes->item(i));
-#endif
+ const XalanNode* const attr = attributes->item(i);
assert(attr != 0);
copyAttributeToTarget(
- *attr,
- contextNode,
- stylesheetTree,
- attList,
- templateChild);
+ attr->getNodeName(),
+ attr->getNodeValue(),
+ attList);
}
}
}
1.73 +17 -25 xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp
Index: XSLTEngineImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- XSLTEngineImpl.hpp 2001/07/12 05:06:04 1.72
+++ XSLTEngineImpl.hpp 2001/07/23 01:39:45 1.73
@@ -589,16 +589,18 @@
* Clone an element with or without children.
*
* @param node node to clone
+ * @param nodeType the type of the node
* @param isLiteral true if a literal element
* @param overrideStrip false if white space stripping
should be done
* @param shouldCloneAttributes true if attributes should be cloned
*/
void
cloneToResultTree(
- XalanNode& node,
- bool isLiteral,
- bool overrideStrip,
- bool shouldCloneAttributes);
+ XalanNode& node,
+ XalanNode::NodeType nodeType,
+ bool isLiteral,
+ bool overrideStrip,
+ bool
shouldCloneAttributes);
/**
* Given a result tree fragment, walk the tree and output it to the
result
@@ -1004,23 +1006,17 @@
XPathExecutionContext& executionContext);
/**
- * Copy an attribute to the created output element, executing attribute
- * templates as need be, and processing the 'xsl:use' attribute.
+ * Copy an attribute to an AttributeListImpl.
*
- * @param attr attribute to copy
- * @param contextNode current context node
- * @param stylesheetTree associated stylesheet object
- * @param attrList attribute list added to
- * @param namespaceContext context for namespace
- * @exception XSLProcessorException
+ * @param attrName The name of the attribute
+ * @param attrValue The value of the attribute
+ * @param attrList The attribute list added to
*/
void
copyAttributeToTarget(
- const XalanAttr& attr,
- XalanNode* contextNode,
- const Stylesheet* stylesheetTree,
- AttributeListImpl& attrList,
- const XalanElement& namespaceContext);
+ const XalanDOMString& attrName,
+ const XalanDOMString& attrValue,
+ AttributeListImpl& attrList);
/**
* Get the factory for making xpaths.
@@ -1462,17 +1458,13 @@
/**
* Copy the attributes from the XSL element to the created
- * output element, executing attribute templates and
- * processing the xsl:use attribute as need be.
- * @exception XSLProcessorException thrown if the active
ProblemListener and XMLParserLiaison decide
- * the error condition is severe enough to halt processing.
+ * output element.
*/
void
copyAttributesToAttList(
- XalanNode* contextNode,
- const Stylesheet* stylesheetTree,
- const XalanElement& templateChild,
- AttributeListImpl& attList);
+ const Stylesheet* stylesheetTree,
+ const XalanNode& node,
+ AttributeListImpl& attList);
// Factory for creating xpaths.
XPathFactory& m_xpathFactory;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]