You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/07/08 00:53:49 UTC
cvs commit: xml-xalan/c/src/XSLT NodeSorter.cpp NodeSorter.hpp
dbertoni 00/07/07 15:53:49
Modified: c/src/XSLT NodeSorter.cpp NodeSorter.hpp
Log:
Cache sort results.
Revision Changes Path
1.10 +89 -18 xml-xalan/c/src/XSLT/NodeSorter.cpp
Index: NodeSorter.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/NodeSorter.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- NodeSorter.cpp 2000/07/06 20:33:37 1.9
+++ NodeSorter.cpp 2000/07/07 22:53:48 1.10
@@ -167,27 +167,12 @@
const NodeSortKey& theKey = m_nodeSortKeys[theKeyIndex];
- const XPath& xpath = theKey.getSelectPattern();
-
- const XObjectGuard r1(
- m_executionContext.getXObjectFactory(),
- xpath.execute(theLHS, theKey.getPrefixResolver(), NodeRefList(), m_executionContext));
- assert(r1.get() != 0);
-
- const XObjectGuard r2(
- m_executionContext.getXObjectFactory(),
- xpath.execute(theRHS, theKey.getPrefixResolver(), NodeRefList(), m_executionContext));
- assert(r2.get() != 0);
-
// Compare as numbers
if(theKey.getTreatAsNumbers() == true)
{
- double n1Num = r1->num();
- double n2Num = r2->num();
+ double n1Num = getNumberResult(theKey, theLHS);
+ double n2Num = getNumberResult(theKey, theRHS);
- const XalanDOMString r1str(r1->str());
- const XalanDOMString r2str(r2->str());
-
if (DoubleSupport::isNaN(n1Num))
n1Num = 0.0;
@@ -222,7 +207,9 @@
// Compare as strings
else
{
- const int theCompareResult = collationCompare(r1->str(), r2->str());
+ const int theCompareResult = collationCompare(
+ getStringResult(theKey, theLHS),
+ getStringResult(theKey, theRHS));
if(0 == theCompareResult)
{
@@ -279,6 +266,90 @@
break;
}
}
+
+ return theResult;
+}
+
+
+
+static const NodeRefList dummy;
+
+
+
+double
+NodeSorter::NodeSortKeyCompare::getNumberResult(
+ const NodeSortKey& theKey,
+ XalanNode* node) const
+{
+ const XPath& xpath = theKey.getSelectPattern();
+
+ const NumberResultsCacheMapType::const_iterator i =
+ m_numberResultsCache.find(&xpath);
+
+ if (i != m_numberResultsCache.end())
+ {
+ const NumberResultsNodeCacheMapType::const_iterator j =
+ i->second.find(node);
+
+ if (j != i->second.end())
+ {
+ // Yuck!!!! Big ugly return here!!!
+ return j->second;
+ }
+ }
+
+ const XObjectGuard result(
+ m_executionContext.getXObjectFactory(),
+ xpath.execute(node, theKey.getPrefixResolver(), dummy, m_executionContext));
+ assert(result.get() != 0);
+
+ const double theResult = result->num();
+
+#if defined(XALAN_NO_MUTABLE)
+ ((NodeSortKeyCompare*)this)->m_numberResultsCache[&xpath][node] = theResult;
+#else
+ m_numberResultsCache[&xpath][node] = theResult;
+#endif
+
+ return theResult;
+}
+
+
+
+const XalanDOMString
+NodeSorter::NodeSortKeyCompare::getStringResult(
+ const NodeSortKey& theKey,
+ XalanNode* node) const
+{
+ const XPath& xpath = theKey.getSelectPattern();
+
+ const StringResultsCacheMapType::const_iterator i =
+ m_stringResultsCache.find(&xpath);
+
+ if (i != m_stringResultsCache.end())
+ {
+ const StringResultsNodeCacheMapType::const_iterator j =
+ i->second.find(node);
+
+ if (j != i->second.end())
+ {
+ // Yuck!!!! Big ugly return here!!!
+ return j->second;
+ }
+ }
+
+ const XObjectGuard result(
+ m_executionContext.getXObjectFactory(),
+ xpath.execute(node, theKey.getPrefixResolver(), dummy, m_executionContext));
+ assert(result.get() != 0);
+
+ const XalanDOMString theResult = result->str();
+
+#if defined(XALAN_NO_MUTABLE)
+ ((NodeSortKeyCompare*)this)->m_stringResultsCache[&xpath][node] = theResult;
+#else
+ m_stringResultsCache[&xpath][node] = theResult;
+#endif
return theResult;
}
1.6 +39 -5 xml-xalan/c/src/XSLT/NodeSorter.hpp
Index: NodeSorter.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/NodeSorter.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NodeSorter.hpp 2000/07/06 20:19:25 1.5
+++ NodeSorter.hpp 2000/07/07 22:53:48 1.6
@@ -70,6 +70,7 @@
#include <functional>
+#include <map>
#include <vector>
@@ -154,7 +155,9 @@
m_executionContext(executionContext),
m_list(theList),
m_nodes(theNodes),
- m_nodeSortKeys(theNodeSortKeys)
+ m_nodeSortKeys(theNodeSortKeys),
+ m_numberResultsCache(),
+ m_stringResultsCache()
{
}
@@ -170,15 +173,46 @@
second_argument_type theRHS,
unsigned int theKeyIndex = 0) const;
- XPathExecutionContext& m_executionContext;
- const MutableNodeRefList& m_list;
- const NodeVectorType& m_nodes;
- const NodeSortKeyVectorType& m_nodeSortKeys;
+ protected:
bool
isNodeBefore(
const XalanNode* node1,
const XalanNode* node2) const;
+
+ double
+ getNumberResult(
+ const NodeSortKey& theKey,
+ XalanNode* node) const;
+
+ const XalanDOMString
+ getStringResult(
+ const NodeSortKey& theKey,
+ XalanNode* node) const;
+
+ private:
+
+ XPathExecutionContext& m_executionContext;
+ const MutableNodeRefList& m_list;
+ const NodeVectorType& m_nodes;
+ const NodeSortKeyVectorType& m_nodeSortKeys;
+
+#if defined(XALAN_NO_NAMESPACES)
+ typedef map<const XalanNode*, double> NumberResultsNodeCacheMapType;
+ typedef map<const XalanNode*, XalanDOMString> StringResultsNodeCacheMapType;
+
+ typedef map<const XPath*, NumberResultsNodeCacheMapType> NumberResultsCacheMapType;
+ typedef map<const XPath*, StringResultsNodeCacheMapType> StringResultsCacheMapType;
+#else
+ typedef std::map<const XalanNode*, double> NumberResultsNodeCacheMapType;
+ typedef std::map<const XalanNode*, XalanDOMString> StringResultsNodeCacheMapType;
+
+ typedef std::map<const XPath*, NumberResultsNodeCacheMapType> NumberResultsCacheMapType;
+ typedef std::map<const XPath*, StringResultsNodeCacheMapType> StringResultsCacheMapType;
+#endif
+
+ mutable NumberResultsCacheMapType m_numberResultsCache;
+ mutable StringResultsCacheMapType m_stringResultsCache;
};
private: