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...@apache.org on 2001/05/17 18:12:39 UTC
cvs commit: xml-xalan/c/src/XPath XObjectFactoryDefault.cpp XObjectFactoryDefault.hpp XPath.cpp XPathExecutionContext.hpp XResultTreeFrag.cpp XResultTreeFrag.hpp
dbertoni 01/05/17 09:12:39
Modified: c/src/XPath XObjectFactoryDefault.cpp
XObjectFactoryDefault.hpp XPath.cpp
XPathExecutionContext.hpp XResultTreeFrag.cpp
XResultTreeFrag.hpp
Log:
Allow for caching of XResultTreeFrag instances.
Revision Changes Path
1.23 +29 -4 xml-xalan/c/src/XPath/XObjectFactoryDefault.cpp
Index: XObjectFactoryDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObjectFactoryDefault.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XObjectFactoryDefault.cpp 2001/03/01 19:01:14 1.22
+++ XObjectFactoryDefault.cpp 2001/05/17 16:12:11 1.23
@@ -96,6 +96,7 @@
m_xobjects(),
m_xnumberCache(),
m_xnodesetCache(),
+ m_xresultTreeFragCache(),
m_XNull(new XNull),
m_xbooleanFalse(new XBoolean(false)),
m_xbooleanTrue(new XBoolean(true))
@@ -263,7 +264,16 @@
static_cast<XResultTreeFrag*>(theXObject);
#endif
- bStatus = m_xresultTreeFragAllocator.destroy(theXResultTreeFrag);
+ if (m_xresultTreeFragCache.size() < eXResultTreeFragCacheMax)
+ {
+ m_xresultTreeFragCache.push_back(theXResultTreeFrag);
+
+ bStatus = true;
+ }
+ else
+ {
+ bStatus = m_xresultTreeFragAllocator.destroy(theXResultTreeFrag);
+ }
}
break;
@@ -503,11 +513,26 @@
const XObjectPtr
XObjectFactoryDefault::createResultTreeFrag(BorrowReturnResultTreeFrag& theValue)
{
- XResultTreeFrag* const theResultTreeFrag = m_xresultTreeFragAllocator.create(theValue);
+ if (m_xresultTreeFragCache.size() > 0)
+ {
+ XResultTreeFrag* const theResultTreeFrag = m_xresultTreeFragCache.back();
- theResultTreeFrag->setFactory(this);
+ m_xresultTreeFragCache.pop_back();
- return XObjectPtr(theResultTreeFrag);
+ theResultTreeFrag->set(theValue);
+
+ return XObjectPtr(theResultTreeFrag);
+ }
+ else
+ {
+ m_xresultTreeFragCache.reserve(eXResultTreeFragCacheMax);
+
+ XResultTreeFrag* const theResultTreeFrag = m_xresultTreeFragAllocator.create(theValue);
+
+ theResultTreeFrag->setFactory(this);
+
+ return XObjectPtr(theResultTreeFrag);
+ }
}
1.22 +12 -7 xml-xalan/c/src/XPath/XObjectFactoryDefault.hpp
Index: XObjectFactoryDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObjectFactoryDefault.hpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- XObjectFactoryDefault.hpp 2001/03/01 19:01:15 1.21
+++ XObjectFactoryDefault.hpp 2001/05/17 16:12:15 1.22
@@ -118,7 +118,8 @@
eDefaultXNodeSetBlockSize = 10,
eDefaultXResultTreeFragBlockSize = 10,
eXNumberCacheMax = 40,
- eXNodeSetCacheMax = 40
+ eXNodeSetCacheMax = 40,
+ eXResultTreeFragCacheMax = 40
};
/**
@@ -192,13 +193,15 @@
createSpan(BorrowReturnMutableNodeRefList& theValue);
#if defined(XALAN_NO_NAMESPACES)
- typedef vector<XObject*> XObjectCollectionType;
- typedef vector<XNumber*> XNumberCacheType;
- typedef vector<XNodeSet*> XNodeSetCacheType;
+ typedef vector<XObject*> XObjectCollectionType;
+ typedef vector<XNumber*> XNumberCacheType;
+ typedef vector<XNodeSet*> XNodeSetCacheType;
+ typedef vector<XResultTreeFrag*> XResultTreeFragCacheType;
#else
- typedef std::vector<XObject*> XObjectCollectionType;
- typedef std::vector<XNumber*> XNumberCacheType;
- typedef std::vector<XNodeSet*> XNodeSetCacheType;
+ typedef std::vector<XObject*> XObjectCollectionType;
+ typedef std::vector<XNumber*> XNumberCacheType;
+ typedef std::vector<XNodeSet*> XNodeSetCacheType;
+ typedef std::vector<XResultTreeFrag*> XResultTreeFragCacheType;
#endif
protected:
@@ -247,6 +250,8 @@
XNumberCacheType m_xnumberCache;
XNodeSetCacheType m_xnodesetCache;
+
+ XResultTreeFragCacheType m_xresultTreeFragCache;
const XalanAutoPtr<XNull> m_XNull;
1.52 +1 -3 xml-xalan/c/src/XPath/XPath.cpp
Index: XPath.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- XPath.cpp 2001/04/30 18:10:59 1.51
+++ XPath.cpp 2001/05/17 16:12:17 1.52
@@ -1009,13 +1009,12 @@
typedef XPathExecutionContext::BorrowReturnMutableNodeRefList BorrowReturnMutableNodeRefList;
BorrowReturnMutableNodeRefList resultNodeList(executionContext);
-
while(m_expression.m_opMap[opPos] != XPathExpression::eENDOP)
{
const int nextOpPos = m_expression.getNextOpCodePosition(opPos);
- const XObjectPtr expr = executeMore(context, opPos, executionContext);
+ const XObjectPtr expr(executeMore(context, opPos, executionContext));
const NodeRefListBase& nl =
expr->nodeset();
@@ -1065,7 +1064,6 @@
const XObject& varName = m_expression.m_tokenQueue[m_expression.m_opMap[opPos + 3]];
- // $$$ ToDo: I don't this will be parsed right in the first place...
const QNameByReference qname(ns.str(),
varName.str());
1.40 +35 -5 xml-xalan/c/src/XPath/XPathExecutionContext.hpp
Index: XPathExecutionContext.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContext.hpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- XPathExecutionContext.hpp 2001/05/14 01:01:16 1.39
+++ XPathExecutionContext.hpp 2001/05/17 16:12:20 1.40
@@ -501,7 +501,7 @@
public:
BorrowReturnResultTreeFrag(XPathExecutionContext& executionContext) :
- m_xpathExecutionContext(executionContext),
+ m_xpathExecutionContext(&executionContext),
m_resultTreeFrag(executionContext.borrowResultTreeFrag())
{
assert(m_resultTreeFrag != 0);
@@ -521,13 +521,28 @@
{
if (m_resultTreeFrag != 0)
{
- if (m_xpathExecutionContext.returnResultTreeFrag(m_resultTreeFrag) == false)
+ if (m_xpathExecutionContext->returnResultTreeFrag(m_resultTreeFrag) == false)
{
delete m_resultTreeFrag;
}
}
}
+ // N.B. Non-const assignment operator semantics.
+ BorrowReturnResultTreeFrag&
+ operator=(BorrowReturnResultTreeFrag& theRHS)
+ {
+ release();
+
+ m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
+
+ m_resultTreeFrag = theRHS.m_resultTreeFrag;
+
+ theRHS.m_resultTreeFrag = 0;
+
+ return *this;
+ }
+
ResultTreeFragBase&
operator*() const
{
@@ -546,11 +561,26 @@
return get();
}
+ void
+ release()
+ {
+ assert(m_xpathExecutionContext != 0);
+
+ if (m_resultTreeFrag != 0)
+ {
+ m_xpathExecutionContext->returnResultTreeFrag(m_resultTreeFrag);
+
+ m_resultTreeFrag = 0;
+ }
+ }
+
BorrowReturnResultTreeFrag
clone(bool deep = false) const
{
+ assert(m_xpathExecutionContext != 0);
+
BorrowReturnResultTreeFrag theResult(
- m_xpathExecutionContext,
+ *m_xpathExecutionContext,
m_resultTreeFrag->clone(deep));
return theResult;
@@ -561,14 +591,14 @@
BorrowReturnResultTreeFrag(
XPathExecutionContext& executionContext,
ResultTreeFragBase* resultTreeFrag) :
- m_xpathExecutionContext(executionContext),
+ m_xpathExecutionContext(&executionContext),
m_resultTreeFrag(resultTreeFrag)
{
assert(m_resultTreeFrag != 0);
}
// Data members...
- XPathExecutionContext& m_xpathExecutionContext;
+ XPathExecutionContext* m_xpathExecutionContext;
ResultTreeFragBase* m_resultTreeFrag;
};
1.21 +22 -0 xml-xalan/c/src/XPath/XResultTreeFrag.cpp
Index: XResultTreeFrag.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XResultTreeFrag.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- XResultTreeFrag.cpp 2001/05/02 15:53:00 1.20
+++ XResultTreeFrag.cpp 2001/05/17 16:12:24 1.21
@@ -339,3 +339,25 @@
{
return m_xresultTreeFrag.indexOf(theNode);
}
+
+
+
+void
+XResultTreeFrag::release()
+{
+ m_value.release();
+
+ clear(m_cachedStringValue);
+
+ m_cachedNumberValue = 0.0;
+}
+
+
+
+void
+XResultTreeFrag::set(BorrowReturnResultTreeFrag& theValue)
+{
+ release();
+
+ m_value = theValue;
+}
1.22 +14 -0 xml-xalan/c/src/XPath/XResultTreeFrag.hpp
Index: XResultTreeFrag.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XResultTreeFrag.hpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- XResultTreeFrag.hpp 2001/05/02 15:53:02 1.21
+++ XResultTreeFrag.hpp 2001/05/17 16:12:25 1.22
@@ -171,6 +171,20 @@
unsigned int
indexOf(const XalanNode* theNode) const;
+ /**
+ * Release the ResultTreeFrag held by the instance.
+ */
+ void
+ release();
+
+ /**
+ * Change the value of an XResultTreeFrag
+ *
+ * @param theValue The new value.
+ */
+ void
+ set(BorrowReturnResultTreeFrag& theValue);
+
private:
class NodeRefListBaseProxy : public NodeRefListBase
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org