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/11/01 16:59:57 UTC
cvs commit: xml-xalan/c/src/XSLT ResultTreeFrag.cpp ResultTreeFrag.hpp StylesheetExecutionContext.hpp StylesheetExecutionContextDefault.cpp StylesheetExecutionContextDefault.hpp XSLTEngineImpl.cpp
dbertoni 01/11/01 07:59:57
Modified: c/src/XSLT ResultTreeFrag.cpp ResultTreeFrag.hpp
StylesheetExecutionContext.hpp
StylesheetExecutionContextDefault.cpp
StylesheetExecutionContextDefault.hpp
XSLTEngineImpl.cpp
Log:
Changes to move XResultTreeFrag to XSLT. amd fixes for addressing RTFs as nodesets.
Revision Changes Path
1.2 +22 -0 xml-xalan/c/src/XSLT/ResultTreeFrag.cpp
Index: ResultTreeFrag.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ResultTreeFrag.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResultTreeFrag.cpp 2001/10/30 04:08:06 1.1
+++ ResultTreeFrag.cpp 2001/11/01 15:59:57 1.2
@@ -96,6 +96,28 @@
+XalanNode*
+ResultTreeFrag::getNodesetRoot() const
+{
+ if (m_documentFragment != 0)
+ {
+ return m_documentFragment;
+ }
+ else
+ {
+ // I hate to do this, but since all of the non-const
+ // member functions will throw exceptions, I can live
+ // with it.
+#if defined(XALAN_OLD_STYLE_CASTS)
+ return (ResultTreeFrag*)this;
+#else
+ return const_cast<ResultTreeFrag*>(this);
+#endif
+ }
+}
+
+
+
void
ResultTreeFrag::clear()
{
1.2 +7 -0 xml-xalan/c/src/XSLT/ResultTreeFrag.hpp
Index: ResultTreeFrag.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ResultTreeFrag.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResultTreeFrag.hpp 2001/10/30 04:08:06 1.1
+++ ResultTreeFrag.hpp 2001/11/01 15:59:57 1.2
@@ -108,6 +108,13 @@
void
clear();
+
+ // These interfaces are inherited from ResultTreeFragBase...
+
+ virtual XalanNode*
+ getNodesetRoot() const;
+
+
// These interfaces are inherited from XalanDocumentFragment...
virtual const XalanDOMString&
1.68 +14 -6 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.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- StylesheetExecutionContext.hpp 2001/10/30 04:11:22 1.67
+++ StylesheetExecutionContext.hpp 2001/11/01 15:59:57 1.68
@@ -141,6 +141,7 @@
class XPath;
class XObject;
class XObjectPtr;
+class XResultTreeFrag;
@@ -1070,6 +1071,19 @@
};
+ /**
+ * This is a hook that XResultTreeFrag instances (which are reference
+ * counted), can notify the owning StylesheetExecutionContext instance
+ * when they are dereferenced and can be cleaned up.
+ *
+ * @param theXResultTreeFrag The instance that is being returned.
+ *
+ * @return true if the XResultTreeFrag instance belongs to the execution context. false if not.
+ */
+ virtual bool
+ returnXResultTreeFrag(XResultTreeFrag* theXResultTreeFrag) = 0;
+
+
enum eDummy
{
eDefaultXMLIndentAmount = 0,
@@ -1595,12 +1609,6 @@
virtual bool
returnMutableNodeRefList(MutableNodeRefList* theList) = 0;
-
- virtual ResultTreeFragBase*
- borrowResultTreeFrag() = 0;
-
- virtual bool
- returnResultTreeFrag(ResultTreeFragBase* theResultTreeFragBase) = 0;
virtual MutableNodeRefList*
createMutableNodeRefList() const = 0;
1.79 +62 -82 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.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- StylesheetExecutionContextDefault.cpp 2001/10/30 04:11:22 1.78
+++ StylesheetExecutionContextDefault.cpp 2001/11/01 15:59:57 1.79
@@ -154,8 +154,10 @@
m_formatterToTextCache(),
m_formatterToSourceTreeCache(),
m_nodeSorterCache(),
- m_resultTreeFragCache(*this, eResultTreeFragCacheListSize),
- m_indentAmount(-1)
+ m_indentAmount(-1),
+ m_xresultTreeFragAllocator(eXResultTreeFragAllocatorBlockSize),
+ m_resultTreeFragAllocator(eResultTreeFragAllocatorBlockSize),
+ m_documentFragmentAllocator(eDocumentFragmentAllocatorBlockSize)
{
}
@@ -189,8 +191,10 @@
m_formatterToTextCache(),
m_formatterToSourceTreeCache(),
m_nodeSorterCache(),
- m_resultTreeFragCache(*this, eResultTreeFragCacheListSize),
- m_indentAmount(-1)
+ m_indentAmount(-1),
+ m_xresultTreeFragAllocator(eXResultTreeFragAllocatorBlockSize),
+ m_resultTreeFragAllocator(eResultTreeFragAllocatorBlockSize),
+ m_documentFragmentAllocator(eDocumentFragmentAllocatorBlockSize)
{
}
@@ -927,7 +931,13 @@
{
assert(m_xsltProcessor != 0);
- BorrowReturnResultTreeFrag theResultTreeFrag(*this);
+ XalanSourceTreeDocumentFragment* const theDocumentFragment =
+ m_documentFragmentAllocator.create(*getSourceTreeFactory());
+ assert(theDocumentFragment != 0);
+
+ ResultTreeFragBase* const theResultTreeFrag =
+ m_resultTreeFragAllocator.create(theDocumentFragment);
+ assert(theResultTreeFrag != 0);
GuardCachedObject<FormatterToSourceTreeCacheType> theGuard(m_formatterToSourceTreeCache);
@@ -938,14 +948,6 @@
theFormatter->setDocument(theDocument);
- XalanSourceTreeDocumentFragment* const theDocumentFragment =
-#if defined(XALAN_OLD_STYLE_CASTS)
- ((const ResultTreeFrag*)theResultTreeFrag.get())->getDocumentFragment();
-#else
- static_cast<const ResultTreeFrag*>(theResultTreeFrag.get())->getDocumentFragment();
-#endif
- assert(theDocumentFragment != 0);
-
theFormatter->setDocumentFragment(theDocumentFragment);
theFormatter->setPrefixResolver(m_xsltProcessor);
@@ -954,9 +956,18 @@
*this,
theFormatter);
+ theFormatter->startDocument();
+
templateChild.executeChildren(*this, sourceNode);
- return getXObjectFactory().createResultTreeFrag(theResultTreeFrag);
+ theFormatter->endDocument();
+
+ XResultTreeFrag* const theXResultTreeFrag =
+ m_xresultTreeFragAllocator.create(*theResultTreeFrag);
+
+ theXResultTreeFrag->setExecutionContext(this);
+
+ return XObjectPtr(theXResultTreeFrag);
}
@@ -1072,6 +1083,40 @@
+bool
+StylesheetExecutionContextDefault::returnXResultTreeFrag(XResultTreeFrag* theXResultTreeFrag)
+{
+ assert(theXResultTreeFrag != 0);
+
+ ResultTreeFragBase* const theResultTreeFragBase =
+ theXResultTreeFrag->release();
+
+ if (m_xresultTreeFragAllocator.destroy(theXResultTreeFrag) == false)
+ {
+ return false;
+ }
+ else
+ {
+ ResultTreeFrag* const theResultTreeFrag =
+#if defined(XALAN_OLD_STYLE_CASTS)
+ (ResultTreeFrag*)theResultTreeFragBase;
+#else
+ static_cast<ResultTreeFrag*>(theResultTreeFragBase);
+#endif
+
+ XalanSourceTreeDocumentFragment* const theDocumentFragment =
+ theResultTreeFrag->getDocumentFragment();
+ assert(theDocumentFragment != 0);
+
+ m_resultTreeFragAllocator.destroy(theResultTreeFrag);
+ m_documentFragmentAllocator.destroy(theDocumentFragment);
+
+ return true;
+ }
+}
+
+
+
FormatterToXML*
StylesheetExecutionContextDefault::createFormatterToXML(
Writer& writer,
@@ -1455,7 +1500,9 @@
m_formatterToTextCache.reset();
m_formatterToSourceTreeCache.reset();
m_nodeSorterCache.reset();
- m_resultTreeFragCache.reset();
+ m_documentFragmentAllocator.reset();
+ m_resultTreeFragAllocator.reset();
+ m_xresultTreeFragAllocator.reset();
// Just in case endDocument() was not called,
// clean things up...
@@ -1614,22 +1661,6 @@
-ResultTreeFragBase*
-StylesheetExecutionContextDefault::borrowResultTreeFrag()
-{
- return m_resultTreeFragCache.get();
-}
-
-
-
-bool
-StylesheetExecutionContextDefault::returnResultTreeFrag(ResultTreeFragBase* theResultTreeFragBase)
-{
- return m_resultTreeFragCache.release(theResultTreeFragBase);
-}
-
-
-
MutableNodeRefList*
StylesheetExecutionContextDefault::createMutableNodeRefList() const
{
@@ -2353,54 +2384,3 @@
-StylesheetExecutionContextDefault::ResultTreeFragCache::ResultTreeFragCache(
- StylesheetExecutionContextDefault& theExecutionContext,
- unsigned int initialSize) :
- m_resultTreeFragCache(initialSize),
- m_documentFragmentCache(initialSize)
-{
- m_documentFragmentCache.m_createFunctor.setExecutionContext(&theExecutionContext);
-}
-
-
-
-StylesheetExecutionContextDefault::ResultTreeFragCache::~ResultTreeFragCache()
-{
-}
-
-
-
-ResultTreeFragBase*
-StylesheetExecutionContextDefault::ResultTreeFragCache::get()
-{
- GuardCachedObject<ResultTreeFragCacheType> theResultTreeFrag(m_resultTreeFragCache);
- assert(theResultTreeFrag.get() != 0);
-
- theResultTreeFrag.get()->setDocumentFragment(m_documentFragmentCache.get());
- assert(theResultTreeFrag.get()->getDocumentFragment() != 0);
-
- return theResultTreeFrag.release();
-}
-
-
-
-bool
-StylesheetExecutionContextDefault::ResultTreeFragCache::release(ResultTreeFragBase* theResultTreeFragBase)
-{
- assert(theResultTreeFragBase != 0);
-
- ResultTreeFrag* const theResultTreeFrag =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (ResultTreeFrag*)theResultTreeFragBase;
-#else
- static_cast<ResultTreeFrag*>(theResultTreeFragBase);
-#endif
-
- XalanSourceTreeDocumentFragment* const theDocumentFragment =
- theResultTreeFrag->getDocumentFragment();
- assert(theDocumentFragment != 0);
-
- m_documentFragmentCache.release(theDocumentFragment);
-
- return m_resultTreeFragCache.release(theResultTreeFrag);
-}
1.71 +15 -108 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.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- StylesheetExecutionContextDefault.hpp 2001/10/30 04:11:22 1.70
+++ StylesheetExecutionContextDefault.hpp 2001/11/01 15:59:57 1.71
@@ -97,8 +97,11 @@
#include <XSLT/CountersTable.hpp>
#include <XSLT/NodeSorter.hpp>
#include <XSLT/ResultTreeFrag.hpp>
+#include <XSLT/ResultTreeFragAllocator.hpp>
#include <XSLT/Stylesheet.hpp>
#include <XSLT/VariablesStack.hpp>
+#include <XSLT/XResultTreeFragAllocator.hpp>
+#include <XSLT/XalanSourceTreeDocumentFragmentAllocator.hpp>
@@ -513,6 +516,9 @@
virtual const ElemTemplateElement*
popElementRecursionStack();
+ virtual bool
+ returnXResultTreeFrag(XResultTreeFrag* theXResultTreeFrag);
+
virtual FormatterToXML*
createFormatterToXML(
Writer& writer,
@@ -799,12 +805,6 @@
virtual bool
returnMutableNodeRefList(MutableNodeRefList* theList);
- virtual ResultTreeFragBase*
- borrowResultTreeFrag();
-
- virtual bool
- returnResultTreeFrag(ResultTreeFragBase* theResultTreeFragBase);
-
virtual MutableNodeRefList*
createMutableNodeRefList() const;
@@ -1011,105 +1011,6 @@
void
cleanUpTransients();
- /**
- *
- * A simple class to cache ResultTreeFrag and
- * XalanSourceTreeDocumentFragment instances.
- *
- */
- class XALAN_XSLT_EXPORT ResultTreeFragCache
- {
- public:
-
- ResultTreeFragCache(
- StylesheetExecutionContextDefault& theExecutionContext,
- unsigned int initialSize);
-
- ~ResultTreeFragCache();
-
- ResultTreeFragBase*
- get();
-
- bool
- release(ResultTreeFragBase* theResultTreeFragBase);
-
- void
- reset()
- {
- m_resultTreeFragCache.reset();
-
- m_documentFragmentCache.reset();
- }
-
- private:
-
- /**
- *
- * A simple functor class to create XalanSourceTreeDocumentFragment
- * instances. This is necessary because the constructor requires
- * a XalanSourceTreeDocument instance.
- *
- */
- class XALAN_XSLT_EXPORT LocalCreateFunctor
- {
- public:
-
- LocalCreateFunctor() :
- m_executionContext(0)
- {
- }
-
- void
- setExecutionContext(StylesheetExecutionContextDefault* theExecutionContext)
- {
- m_executionContext = theExecutionContext;
- }
-
- XalanSourceTreeDocumentFragment*
- operator()() const
- {
- assert(m_executionContext != 0);
-
- return new XalanSourceTreeDocumentFragment(*m_executionContext->getSourceTreeFactory());
- }
-
- StylesheetExecutionContextDefault* m_executionContext;
- };
-
- /**
- *
- * A simple functor class to clear the children from a
- * XalanSourceTreeDocumentFragment so it can be re-used.
- *
- */
- class XALAN_XSLT_EXPORT LocalResetFunctor
- {
- public:
-
- void
- operator()(XalanSourceTreeDocumentFragment* theInstance) const
- {
- theInstance->clearChildren();
- }
- };
-
- typedef XalanObjectCache<
- ResultTreeFrag,
- DefaultCacheCreateFunctor<ResultTreeFrag>,
- DeleteFunctor<ResultTreeFrag>,
- ClearCacheResetFunctor<ResultTreeFrag> > ResultTreeFragCacheType;
-
- typedef XalanObjectCache<
- XalanSourceTreeDocumentFragment,
- LocalCreateFunctor,
- DeleteFunctor<XalanSourceTreeDocumentFragment>,
- LocalResetFunctor> DocumentFragmentCacheType;
-
- ResultTreeFragCacheType m_resultTreeFragCache;
-
- DocumentFragmentCacheType m_documentFragmentCache;
- };
-
XPathExecutionContextDefault m_xpathExecutionContextDefault;
// $$ ToDo: Try to remove this dependency, and rely only on XSLTProcessor...
@@ -1119,7 +1020,9 @@
enum { eXPathCacheMax = 50,
eDefaultParamsVectorSize = 10,
- eResultTreeFragCacheListSize = 50 };
+ eXResultTreeFragAllocatorBlockSize = 10,
+ eResultTreeFragAllocatorBlockSize = 10,
+ eDocumentFragmentAllocatorBlockSize = 10 };
ElementRecursionStackType m_elementRecursionStack;
@@ -1174,9 +1077,13 @@
NodeSorterCacheType m_nodeSorterCache;
- ResultTreeFragCache m_resultTreeFragCache;
-
int m_indentAmount;
+
+ XResultTreeFragAllocator m_xresultTreeFragAllocator;
+
+ ResultTreeFragAllocator m_resultTreeFragAllocator;
+
+ XalanSourceTreeDocumentFragmentAllocator m_documentFragmentAllocator;
static XalanNumberFormatFactory s_defaultXalanNumberFormatFactory;
1.125 +0 -1 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.124
retrieving revision 1.125
diff -u -r1.124 -r1.125
--- XSLTEngineImpl.cpp 2001/10/30 04:09:52 1.124
+++ XSLTEngineImpl.cpp 2001/11/01 15:59:57 1.125
@@ -118,7 +118,6 @@
#include <XPath/XPathExecutionContextDefault.hpp>
#include <XPath/XPathFactory.hpp>
#include <XPath/XPathProcessorImpl.hpp>
-#include <XPath/XResultTreeFrag.hpp>
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org