dbertoni    01/01/17 08:57:42

  Modified:    c/src/XPath XNodeSet.cpp XNodeSet.hpp
                        XObjectFactoryDefault.cpp XObjectFactoryDefault.hpp
                        XPathExecutionContext.hpp
  Log:
  Enable caching and re-use of XNodeSet instances.
  
  Revision  Changes    Path
  1.21      +28 -2     xml-xalan/c/src/XPath/XNodeSet.cpp
  
  Index: XNodeSet.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XNodeSet.cpp,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- XNodeSet.cpp      2001/01/16 02:32:39     1.20
  +++ XNodeSet.cpp      2001/01/17 16:57:32     1.21
  @@ -79,12 +79,16 @@
   
   
   
  +const double theBogusNumberValue = 123456789;
  +
  +
  +
   XNodeSet::XNodeSet(BorrowReturnMutableNodeRefList&   value) :
        XObject(eTypeNodeSet),
        m_value(value),
        m_resultTreeFrag(),
        m_cachedStringValue(),
  -     m_cachedNumberValue(0.0)        
  +     m_cachedNumberValue(theBogusNumberValue)
   {
   }
   
  @@ -133,7 +137,7 @@
   double
   XNodeSet::num() const
   {
  -     if (m_cachedNumberValue == 0.0)
  +     if (DoubleSupport::equal(m_cachedNumberValue, theBogusNumberValue) == 
true)
        {
   #if defined(XALAN_NO_MUTABLE)
                ((XNodeSet*)this)->m_cachedNumberValue = 
DoubleSupport::toDouble(str());
  @@ -228,4 +232,26 @@
   {
        theCallbackObject.NodeSet(*this,
                                                          nodeset());
  +}
  +
  +
  +
  +void
  +XNodeSet::release()
  +{
  +     m_value.release();
  +
  +     m_cachedNumberValue = theBogusNumberValue;
  +
  +     clear(m_cachedStringValue);
  +}
  +
  +
  +
  +void
  +XNodeSet::set(BorrowReturnMutableNodeRefList&        value)
  +{
  +     release();
  +
  +     m_value = value;
   }
  
  
  
  1.18      +15 -1     xml-xalan/c/src/XPath/XNodeSet.hpp
  
  Index: XNodeSet.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XNodeSet.hpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XNodeSet.hpp      2001/01/16 02:32:39     1.17
  +++ XNodeSet.hpp      2001/01/17 16:57:34     1.18
  @@ -147,6 +147,20 @@
        virtual void
        ProcessXObjectTypeCallback(XObjectTypeCallback&         
theCallbackObject) const;
   
  +     /**
  +      * Release the node set held by the instance.
  +      */
  +     void
  +     release();
  +
  +     /**
  +      * Change the value of an XNodeSet
  +      *
  +      * @param theValue The new value.
  +      */
  +     void
  +     set(BorrowReturnMutableNodeRefList&             value);
  +
   private:
   
        // Not implemented...
  @@ -156,7 +170,7 @@
        // Data members...
   
   
  -     const BorrowReturnMutableNodeRefList            m_value;
  +     BorrowReturnMutableNodeRefList                          m_value;
   
        mutable XalanAutoPtr<ResultTreeFragBase>        m_resultTreeFrag;
   
  
  
  
  1.20      +34 -5     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- XObjectFactoryDefault.cpp 2001/01/16 02:34:45     1.19
  +++ XObjectFactoryDefault.cpp 2001/01/17 16:57:35     1.20
  @@ -100,6 +100,7 @@
        m_xtokenStringAdapterAllocator(theXStringBlockSize),
        m_xobjects(),
        m_xnumberCache(),
  +     m_xnodesetCache(),
        m_XNull(new XNull)
   {
   }
  @@ -234,14 +235,25 @@
   
        case XObject::eTypeNodeSet:
                {
  -                     XNodeSet* const theXNodeSet =
  +                     XNodeSet* const         theXNodeSet =
   #if defined(XALAN_OLD_STYLE_CASTS)
                                (XNodeSet*)theXObject;
   #else
                                static_cast<XNodeSet*>(theXObject);
   #endif
   
  -                     bStatus = m_xnodesetAllocator.destroy(theXNodeSet);
  +                     if (m_xnodesetCache.size() < eXNodeSetCacheMax)
  +                     {
  +                             theXNodeSet->release();
  +
  +                             m_xnodesetCache.push_back(theXNodeSet);
  +
  +                             bStatus = true;
  +                     }
  +                     else
  +                     {
  +                             bStatus = 
m_xnodesetAllocator.destroy(theXNodeSet);
  +                     }
                }
                break;
   
  @@ -370,11 +382,26 @@
   const XObjectPtr
   XObjectFactoryDefault::createNodeSet(BorrowReturnMutableNodeRefList& 
theValue)
   {
  -     XNodeSet* const         theXNodeSet = 
m_xnodesetAllocator.createNodeSet(theValue);
  +     if (m_xnodesetCache.size() > 0)
  +     {
  +             XNodeSet* const         theXObject = m_xnodesetCache.back();
   
  -     theXNodeSet->setFactory(this);
  +             m_xnodesetCache.pop_back();
   
  -     return XObjectPtr(theXNodeSet);
  +             theXObject->set(theValue);
  +
  +             return XObjectPtr(theXObject);
  +     }
  +     else
  +     {
  +             m_xnodesetCache.reserve(eXNodeSetCacheMax);
  +
  +             XNodeSet* const         theXObject = 
m_xnodesetAllocator.createNodeSet(theValue);
  +
  +             theXObject->setFactory(this);
  +
  +             return XObjectPtr(theXObject);
  +     }
   }
   
   
  @@ -503,4 +530,6 @@
        m_xobjects.clear();
   
        m_xnumberCache.clear();
  +
  +     m_xnodesetCache.clear();
   }
  
  
  
  1.19      +11 -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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- XObjectFactoryDefault.hpp 2001/01/16 02:34:45     1.18
  +++ XObjectFactoryDefault.hpp 2001/01/17 16:57:36     1.19
  @@ -114,7 +114,9 @@
                eDefaultXStringBlockSize = 10,
                eDefaultXNumberBlockSize = 10,
                eDefaultXNodeSetBlockSize = 10,
  -             eDefaultXResultTreeFragBlockSize = 10
  +             eDefaultXResultTreeFragBlockSize = 10,
  +             eXNumberCacheMax = 40,
  +             eXNodeSetCacheMax = 40
        };
        
        /**
  @@ -188,11 +190,13 @@
        createSpan(BorrowReturnMutableNodeRefList&      theValue);
   
   #if defined(XALAN_NO_NAMESPACES)
  -     typedef set<XObject*, less<XObject*> >          CollectionType;
  -     typedef vector<XNumber*>, less<XNumber*> >      XNumberCacheType;
  +     typedef set<XObject*, less<XObject*> >  CollectionType;
  +     typedef vector<XNumber*>                                
XNumberCacheType;
  +     typedef vector<XNodeSet*>                               
XNodeSetCacheType;
   #else
  -     typedef std::set<XObject*>                                      
CollectionType;
  -     typedef std::vector<XNumber*>                           
XNumberCacheType;
  +     typedef std::set<XObject*>                      CollectionType;
  +     typedef std::vector<XNumber*>           XNumberCacheType;
  +     typedef std::vector<XNodeSet*>          XNodeSetCacheType;
   #endif
   
   protected:
  @@ -204,8 +208,6 @@
   
   private:
   
  -     enum { eXNumberCacheMax = 40 };
  -
        // Not implemented...
        XObjectFactoryDefault(const XObjectFactoryDefault&);
   
  @@ -241,6 +243,8 @@
        CollectionType                                  m_xobjects;
   
        XNumberCacheType                                m_xnumberCache;
  +
  +     XNodeSetCacheType                               m_xnodesetCache;
   
        const XalanAutoPtr<XNull>               m_XNull;
   };
  
  
  
  1.35      +36 -7     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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- XPathExecutionContext.hpp 2001/01/16 02:34:46     1.34
  +++ XPathExecutionContext.hpp 2001/01/17 16:57:37     1.35
  @@ -353,7 +353,7 @@
        public:
   
                BorrowReturnMutableNodeRefList(XPathExecutionContext&   
executionContext) :
  -                     m_xpathExecutionContext(executionContext),
  +                     m_xpathExecutionContext(&executionContext),
                        
m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
                {
                        assert(m_mutableNodeRefList != 0);
  @@ -371,15 +371,14 @@
   
                ~BorrowReturnMutableNodeRefList()
                {
  -                     if (m_mutableNodeRefList != 0)
  -                     {
  -                             
m_xpathExecutionContext.returnMutableNodeRefList(m_mutableNodeRefList);
  -                     }
  +                     release();
                }
   
                MutableNodeRefList&
                operator*() const
                {
  +                     assert(m_mutableNodeRefList != 0);
  +
                        return *m_mutableNodeRefList;
                }
   
  @@ -395,19 +394,49 @@
                        return get();
                }
   
  +             void
  +             release()
  +             {
  +                     assert(m_xpathExecutionContext != 0);
  +
  +                     if (m_mutableNodeRefList != 0)
  +                     {
  +                             
m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
  +
  +                             m_mutableNodeRefList = 0;
  +                     }
  +             }
  +
                BorrowReturnMutableNodeRefList
                clone() const
                {
  -                     BorrowReturnMutableNodeRefList  
theResult(m_xpathExecutionContext);
  +                     assert(m_xpathExecutionContext != 0);
  +
  +                     BorrowReturnMutableNodeRefList  
theResult(*m_xpathExecutionContext);
   
                        *theResult = *m_mutableNodeRefList;
   
                        return theResult;
                }
   
  +             // N.B. Non-const assignment operator semantics.
  +             BorrowReturnMutableNodeRefList&
  +             operator=(BorrowReturnMutableNodeRefList&       theRHS)
  +             {
  +                     release();
  +
  +                     m_xpathExecutionContext = 
theRHS.m_xpathExecutionContext;
  +
  +                     m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
  +
  +                     theRHS.m_mutableNodeRefList = 0;
  +
  +                     return *this;
  +             }
  +
        private:
   
  -             XPathExecutionContext&  m_xpathExecutionContext;
  +             XPathExecutionContext*  m_xpathExecutionContext;
   
                MutableNodeRefList*             m_mutableNodeRefList;
        };
  
  
  

Reply via email to