dbertoni    01/04/10 19:36:23

  Modified:    c/src/XSLT ElemTemplateElement.cpp
                        StylesheetExecutionContext.cpp
                        StylesheetExecutionContext.hpp
                        StylesheetExecutionContextDefault.cpp
                        StylesheetExecutionContextDefault.hpp
                        StylesheetRoot.cpp
  Log:
  Changes to allow for caching of FormatterToText instances.
  
  Revision  Changes    Path
  1.53      +13 -4     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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ElemTemplateElement.cpp   2001/03/29 22:24:25     1.52
  +++ ElemTemplateElement.cpp   2001/04/11 02:36:21     1.53
  @@ -327,16 +327,25 @@
        // a string.
        DOMStringPrintWriter            thePrintWriter(result);
   
  -     // Create a FormatterToText, and don't normalize CR/LF, since we don't 
want
  -     // this text to be normalized.  Finally, handle any ignorable 
whitespace events.
  -     FormatterToText                         theFormatter(thePrintWriter, 
false, true);
  +     // Borrow a FormatterToText, and don't normalize CR/LF, since we don't 
want
  +     // this text to be normalized.  Finally, have the formatter handle any 
ignorable
  +     // whitespace events.
  +     StylesheetExecutionContext::BorrowReturnFormatterToText theFormatter(
  +                             executionContext,
  +                             thePrintWriter,
  +                             false,
  +                             true);
   
        // Create an object to set and restore the execution state.
        StylesheetExecutionContext::OutputContextPushPop        
theOutputContextPushPop(
                                        executionContext,
  -                                     &theFormatter);
  +                                     theFormatter.get());
   
  +     theFormatter->startDocument();
  +
        executeChildren(executionContext);
  +
  +     theFormatter->endDocument();
   }
   
   
  
  
  
  1.7       +22 -0     xml-xalan/c/src/XSLT/StylesheetExecutionContext.cpp
  
  Index: StylesheetExecutionContext.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContext.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StylesheetExecutionContext.cpp    2001/03/06 21:22:59     1.6
  +++ StylesheetExecutionContext.cpp    2001/04/11 02:36:21     1.7
  @@ -59,6 +59,10 @@
   
   
   
  +#include <XMLSupport/FormatterToText.hpp>
  +
  +
  +
   #include "ElemTemplateElement.hpp"
   
   
  @@ -104,4 +108,22 @@
        m_executionContext.popContextMarker();
   
        m_executionContext.setCurrentStackFrameIndex(m_savedStackFrameIndex);
  +}
  +
  +
  +
  
+StylesheetExecutionContext::BorrowReturnFormatterToText::BorrowReturnFormatterToText(
  +                     StylesheetExecutionContext&             
executionContext,
  +                     Writer&                                                 
writer,
  +                     bool                                                    
normalizeLinefeed,
  +                     bool                                                    
handleIgnorableWhitespace)  :
  +     m_executionContext(executionContext),
  +     m_formatter(executionContext.borrowFormatterToText())
  +{
  +     assert(m_formatter != 0);
  +
  +     m_formatter->setNormalizeLinefeed(normalizeLinefeed);
  +     m_formatter->setHandleIgnorableWhitespace(handleIgnorableWhitespace);
  +     m_formatter->clearEncoding();
  +     m_formatter->setWriter(&writer);
   }
  
  
  
  1.51      +63 -0     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.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- StylesheetExecutionContext.hpp    2001/03/29 22:24:26     1.50
  +++ StylesheetExecutionContext.hpp    2001/04/11 02:36:21     1.51
  @@ -1162,6 +1162,69 @@
                        Writer&                                 writer,
                        const XalanDOMString&   encoding) = 0;
   
  +     /**
  +      * Borrow a cached FormatterToText instance.
  +      *
  +      * @return A pointer to the instance.
  +      */
  +     virtual FormatterToText*
  +     borrowFormatterToText() = 0;
  +
  +     /**
  +      * Return a previously borrowed FormatterToText instance.
  +      *
  +      * @param theFormatter A pointer the to previously borrowed instance.
  +      * @return true if the formatter was borrowed (at therefore, 
destroyed), false if not.
  +      */
  +     virtual bool
  +     returnFormatterToText(FormatterToText*  theFormatter) = 0;
  +
  +     class BorrowReturnFormatterToText
  +     {
  +     public:
  +
  +             BorrowReturnFormatterToText(
  +                             StylesheetExecutionContext&             
executionContext,
  +                             Writer&                                         
        writer,
  +                             bool                                            
        normalizeLinefeed = true,
  +                             bool                                            
        handleIgnorableWhitespace = true);
  +
  +             ~BorrowReturnFormatterToText()
  +             {
  +                     assert(m_formatter != 0);
  +
  +                     m_executionContext.returnFormatterToText(m_formatter);
  +             }
  +
  +             FormatterToText&
  +             operator*() const
  +             {
  +                     assert(m_formatter != 0);
  +
  +                     return *m_formatter;
  +             }
  +
  +             FormatterToText*
  +             get() const
  +             {
  +                     assert(m_formatter != 0);
  +
  +                     return m_formatter;
  +             }
  +
  +             FormatterToText*
  +             operator->() const
  +             {
  +                     return get();
  +             }
  +
  +     private:
  +
  +             StylesheetExecutionContext&             m_executionContext;
  +
  +             FormatterToText*                                m_formatter;
  +     };
  +
   
        typedef XalanAutoPtr<XalanNumberFormat>         
XalanNumberFormatAutoPtr;
   
  
  
  
  1.61      +72 -2     
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.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- StylesheetExecutionContextDefault.cpp     2001/03/29 22:24:26     1.60
  +++ StylesheetExecutionContextDefault.cpp     2001/04/11 02:36:22     1.61
  @@ -148,7 +148,9 @@
        m_useDOMResultTreeFactory(false),
        m_ignoreHTMLElementNamespaces(false),
        m_sourceTreeResultTreeFactory(),
  -     m_mode(0)
  +     m_mode(0),
  +     m_availableCachedFormattersToText(),
  +     m_busyCachedFormattersToText()
   {
   }
   
  @@ -179,7 +181,9 @@
        m_useDOMResultTreeFactory(false),
        m_ignoreHTMLElementNamespaces(false),
        m_sourceTreeResultTreeFactory(),
  -     m_mode(0)
  +     m_mode(0),
  +     m_availableCachedFormattersToText(),
  +     m_busyCachedFormattersToText()
   {
   }
   
  @@ -188,6 +192,15 @@
   StylesheetExecutionContextDefault::~StylesheetExecutionContextDefault()
   {
        reset();
  +
  +#if !defined(XALAN_NO_NAMESPACES)
  +     using std::for_each;
  +#endif
  +
  +     for_each(
  +             m_availableCachedFormattersToText.begin(),
  +             m_availableCachedFormattersToText.end(),
  +             DeleteFunctor<FormatterToText>());
   }
   
   
  @@ -1202,6 +1215,56 @@
   
   
   
  +FormatterToText*
  +StylesheetExecutionContextDefault::borrowFormatterToText()
  +{
  +     // We'll always return the back of the free list, since
  +     // that's the cheapest thing.
  +     if (m_availableCachedFormattersToText.size() == 0)
  +     {
  +             m_busyCachedFormattersToText.push_back(new FormatterToText);
  +     }
  +     else
  +     {
  +             
m_busyCachedFormattersToText.push_back(m_availableCachedFormattersToText.back());
  +
  +             m_availableCachedFormattersToText.pop_back();
  +     }
  +
  +     return m_busyCachedFormattersToText.back();
  +}
  +
  +
  +
  +bool
  +StylesheetExecutionContextDefault::returnFormatterToText(FormatterToText*    
theFormatter)
  +{
  +#if !defined(XALAN_NO_NAMESPACES)
  +     using std::find;
  +#endif
  +
  +     const FormatterToTextCacheType::iterator        i =
  +             find(
  +                     m_busyCachedFormattersToText.begin(),
  +                     m_busyCachedFormattersToText.end(),
  +                     theFormatter);
  +
  +     if (i == m_busyCachedFormattersToText.end())
  +     {
  +             return false;
  +     }
  +     else
  +     {
  +             m_availableCachedFormattersToText.push_back(theFormatter);
  +
  +             m_busyCachedFormattersToText.erase(i);
  +
  +             return true;
  +     }
  +}
  +
  +
  +
   StylesheetExecutionContextDefault::XalanNumberFormatAutoPtr
   StylesheetExecutionContextDefault::createXalanNumberFormat()
   {
  @@ -1430,6 +1493,13 @@
        }
   
        m_mode = 0;
  +
  +     while (m_busyCachedFormattersToText.size() != 0)
  +     {
  +             
m_availableCachedFormattersToText.push_back(m_busyCachedFormattersToText.back());
  +
  +             m_busyCachedFormattersToText.pop_back();
  +     }
   
        // Just in case endDocument() was not called,
        // clean things up...
  
  
  
  1.55      +12 -0     
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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- StylesheetExecutionContextDefault.hpp     2001/03/30 19:30:47     1.54
  +++ StylesheetExecutionContextDefault.hpp     2001/04/11 02:36:22     1.55
  @@ -118,6 +118,7 @@
        typedef map<XalanDOMString,
                                XPathCacheEntry,
                                less<XalanDOMString> >                          
        XPathCacheMapType;
  +     typedef vector<FormatterToText*>                                        
FormatterToTextCacheType;
   #else
        typedef std::deque<const ElemTemplateElement*>          
ElementRecursionStackType;
        typedef std::set<FormatterListener*>                            
FormatterListenerSetType;
  @@ -126,6 +127,7 @@
        typedef std::set<const KeyDeclaration*>                         
KeyDeclarationSetType;
        typedef std::pair<const XPath*, clock_t>                        
XPathCacheEntry;
        typedef std::map<XalanDOMString, XPathCacheEntry>       
XPathCacheMapType;
  +     typedef std::vector<FormatterToText*>                           
FormatterToTextCacheType;
   #endif
   
        typedef Stylesheet::KeyTablesTableType                          
KeyTablesTableType;
  @@ -563,6 +565,12 @@
                        Writer&                                 writer,
                        const XalanDOMString&   encoding);
   
  +     virtual FormatterToText*
  +     borrowFormatterToText();
  +
  +     virtual bool
  +     returnFormatterToText(FormatterToText*  theFormatter);
  +
        virtual XalanNumberFormatAutoPtr
        createXalanNumberFormat();
   
  @@ -1020,6 +1028,10 @@
   
        // Holds the current mode.
        const QName*                        m_mode;
  +
  +     FormatterToTextCacheType                        
m_availableCachedFormattersToText;
  +
  +     FormatterToTextCacheType                        
m_busyCachedFormattersToText;
   
        /**
         * The factory that will be used to create result tree fragments based 
on our
  
  
  
  1.41      +1 -1      xml-xalan/c/src/XSLT/StylesheetRoot.cpp
  
  Index: StylesheetRoot.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetRoot.cpp,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- StylesheetRoot.cpp        2001/03/29 22:24:26     1.40
  +++ StylesheetRoot.cpp        2001/04/11 02:36:22     1.41
  @@ -119,7 +119,7 @@
   
   
   
  -//#define XALAN_VQ_SPECIAL_TRACE
  +#define XALAN_VQ_SPECIAL_TRACE
   #if defined(XALAN_VQ_SPECIAL_TRACE)
   #include "d:/Rational/Quantify/pure.h"
   #endif
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to