dbertoni 02/04/06 11:35:58
Modified: c/src/XSLT XSLTEngineImpl.cpp XSLTEngineImpl.hpp
Log:
More efficient xsl:strip-space and xsl:preserve-space processing.
Revision Changes Path
1.138 +90 -82 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.137
retrieving revision 1.138
diff -u -r1.137 -r1.138
--- XSLTEngineImpl.cpp 2 Apr 2002 06:13:16 -0000 1.137
+++ XSLTEngineImpl.cpp 6 Apr 2002 19:35:58 -0000 1.138
@@ -193,7 +193,8 @@
m_outputContextStack(),
m_resultNamespacesStack(),
m_dummyAttributesList(),
- m_scratchString()
+ m_scratchString(),
+ m_hasStripOrPreserveSpace(false)
{
m_outputContextStack.pushContext();
}
@@ -226,6 +227,8 @@
m_domSupport.reset();
m_resultNamespacesStack.clear();
+
+ m_hasStripOrPreserveSpace = false;
}
@@ -305,7 +308,7 @@
{
if(XalanNode::PROCESSING_INSTRUCTION_NODE ==
child->getNodeType())
{
- const XalanDOMString nodeName(child->getNodeName());
+ const XalanDOMString& nodeName =
child->getNodeName();
if(equals(nodeName, stylesheetNodeName))
{
@@ -402,12 +405,15 @@
theFormatter->setPrefixResolver(this);
}
+ m_hasStripOrPreserveSpace =
m_stylesheetRoot->getWhitespacePreservingElements().size() > 0 ||
+ m_stylesheetRoot->getWhitespaceStrippingElements().size() > 0;
+
m_stylesheetRoot->process(sourceTree, outputTarget, executionContext);
+ }
- if(0 != m_diagnosticsPrintWriter)
- {
-
displayDuration(StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("Total time")),
&totalTimeID);
- }
+ if(0 != m_diagnosticsPrintWriter)
+ {
+
displayDuration(StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("Total time")),
&totalTimeID);
}
}
@@ -438,11 +444,14 @@
FormatterListener* const theFormatter =
outputTarget.getDocumentHandler();
- if (theFormatter != 0)
+ if (theFormatter != 0 && theFormatter->getPrefixResolver() == 0)
{
theFormatter->setPrefixResolver(this);
}
+ m_hasStripOrPreserveSpace =
m_stylesheetRoot->getWhitespacePreservingElements().size() > 0 ||
+ m_stylesheetRoot->getWhitespaceStrippingElements().size() > 0;
+
m_stylesheetRoot->process(sourceTree, outputTarget, executionContext);
}
@@ -2939,7 +2948,7 @@
XPathExecutionContext& executionContext,
const XalanNode& textNode) const
{
- if (m_stylesheetRoot == 0)
+ if (m_hasStripOrPreserveSpace == false || m_stylesheetRoot == 0)
{
return false;
}
@@ -2947,118 +2956,117 @@
{
bool strip = false; // return value
- if((m_stylesheetRoot->getWhitespacePreservingElements().size() > 0 ||
- m_stylesheetRoot->getWhitespaceStrippingElements().size() > 0))
- {
- const XalanNode::NodeType type = textNode.getNodeType();
+ assert(m_stylesheetRoot->getWhitespacePreservingElements().size() > 0
||
+ m_stylesheetRoot->getWhitespaceStrippingElements().size() >
0);
- if(XalanNode::TEXT_NODE == type ||
XalanNode::CDATA_SECTION_NODE == type)
- {
- const XalanText& theTextNode =
+ const XalanNode::NodeType type = textNode.getNodeType();
+
+ if(XalanNode::TEXT_NODE == type || XalanNode::CDATA_SECTION_NODE ==
type)
+ {
+ const XalanText& theTextNode =
#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanText&)textNode;
+ (const XalanText&)textNode;
#else
- static_cast<const
XalanText&>(textNode);
+ static_cast<const XalanText&>(textNode);
#endif
- if(!theTextNode.isIgnorableWhitespace())
- {
- const XalanDOMString& data =
theTextNode.getData();
+ if(!theTextNode.isIgnorableWhitespace())
+ {
+ const XalanDOMString& data = theTextNode.getData();
- if(0 == length(data))
- {
- return true;
- }
- else if(!isXMLWhitespace(data))
- {
- return false;
- }
+ if(0 == length(data))
+ {
+ return true;
+ }
+ else if(!isXMLWhitespace(data))
+ {
+ return false;
}
+ }
- XalanNode* parent =
DOMServices::getParentOfNode(textNode);
+ XalanNode* parent =
DOMServices::getParentOfNode(textNode);
- while(0 != parent)
+ while(0 != parent)
+ {
+ if(parent->getNodeType() == XalanNode::ELEMENT_NODE)
{
- if(parent->getNodeType() ==
XalanNode::ELEMENT_NODE)
- {
- const XalanElement* const
parentElem =
+ const XalanElement* const parentElem =
#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanElement*)parent;
+ (const XalanElement*)parent;
#else
- static_cast<const
XalanElement*>(parent);
+ static_cast<const
XalanElement*>(parent);
#endif
- XPath::eMatchScore
highPreserveScore = XPath::eMatchScoreNone;
- XPath::eMatchScore highStripScore
= XPath::eMatchScoreNone;
+ XPath::eMatchScore highPreserveScore =
XPath::eMatchScoreNone;
+ XPath::eMatchScore highStripScore =
XPath::eMatchScoreNone;
- ElementPrefixResolverProxy
theProxy(parentElem, m_xpathEnvSupport, m_domSupport);
+ ElementPrefixResolverProxy
theProxy(parentElem, m_xpathEnvSupport, m_domSupport);
- {
- // $$$ ToDo: All of this
should be moved into a member of
- // Stylesheet, so as not to
expose these two data members...
- typedef
Stylesheet::XPathVectorType XPathVectorType;
+ {
+ // $$$ ToDo: All of this should be
moved into a member of
+ // Stylesheet, so as not to expose
these two data members...
+ typedef Stylesheet::XPathVectorType
XPathVectorType;
- const XPathVectorType&
theElements =
+ const XPathVectorType& theElements =
m_stylesheetRoot->getWhitespacePreservingElements();
- const
XPathVectorType::size_type nTests =
+ const XPathVectorType::size_type
nTests =
theElements.size();
- for(XPathVectorType::size_type
i = 0; i < nTests; i++)
- {
- const XPath* const
matchPat = theElements[i];
- assert(matchPat != 0);
+ for(XPathVectorType::size_type i = 0;
i < nTests; i++)
+ {
+ const XPath* const
matchPat = theElements[i];
+ assert(matchPat != 0);
- const
XPath::eMatchScore score = matchPat->getMatchScore(parent, theProxy,
executionContext);
+ const XPath::eMatchScore
score = matchPat->getMatchScore(parent, theProxy, executionContext);
- if(score >
highPreserveScore)
-
highPreserveScore = score;
- }
+ if(score > highPreserveScore)
+ highPreserveScore =
score;
}
+ }
- {
- typedef
Stylesheet::XPathVectorType XPathVectorType;
+ {
+ typedef Stylesheet::XPathVectorType
XPathVectorType;
- const XPathVectorType&
theElements =
+ const XPathVectorType& theElements =
m_stylesheetRoot->getWhitespaceStrippingElements();
- const
XPathVectorType::size_type nTests =
- theElements.size();
+ const XPathVectorType::size_type
nTests =
+ theElements.size();
- for(XPathVectorType::size_type
i = 0; i < nTests; i++)
- {
- const XPath* const
matchPat =
+ for(XPathVectorType::size_type i = 0;
i < nTests; i++)
+ {
+ const XPath* const
matchPat =
theElements[i];
- assert(matchPat != 0);
+ assert(matchPat != 0);
- const
XPath::eMatchScore score = matchPat->getMatchScore(parent, theProxy,
executionContext);
+ const XPath::eMatchScore
score = matchPat->getMatchScore(parent, theProxy, executionContext);
- if(score >
highStripScore)
- highStripScore
= score;
- }
+ if(score > highStripScore)
+ highStripScore = score;
}
+ }
- if(highPreserveScore >
XPath::eMatchScoreNone ||
- highStripScore >
XPath::eMatchScoreNone)
+ if(highPreserveScore > XPath::eMatchScoreNone
||
+ highStripScore > XPath::eMatchScoreNone)
+ {
+ if(highPreserveScore > highStripScore)
{
- if(highPreserveScore >
highStripScore)
- {
- strip = false;
- }
- else if(highStripScore >
highPreserveScore)
- {
- strip = true;
- }
- else
- {
- warn("Match conflict
between xsl:strip-space and xsl:preserve-space");
- }
- break;
+ strip = false;
}
+ else if(highStripScore >
highPreserveScore)
+ {
+ strip = true;
+ }
+ else
+ {
+ warn("Match conflict between
xsl:strip-space and xsl:preserve-space");
+ }
+ break;
}
-
- parent = parent->getParentNode();
}
+
+ parent = parent->getParentNode();
}
}
1.82 +2 -0 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.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- XSLTEngineImpl.hpp 28 Mar 2002 07:07:56 -0000 1.81
+++ XSLTEngineImpl.hpp 6 Apr 2002 19:35:58 -0000 1.82
@@ -1642,6 +1642,8 @@
XalanDOMString m_scratchString;
+ bool
m_hasStripOrPreserveSpace;
+
static void
installFunctions();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
