dbertoni    2002/12/04 13:45:40

  Modified:    c/src/XPath XPathExecutionContextDefault.cpp
                        XPathExecutionContextDefault.hpp
  Log:
  Cache position in context node list.
  
  Revision  Changes    Path
  1.55      +31 -7     xml-xalan/c/src/XPath/XPathExecutionContextDefault.cpp
  
  Index: XPathExecutionContextDefault.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContextDefault.cpp,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- XPathExecutionContextDefault.cpp  21 Nov 2002 01:26:18 -0000      1.54
  +++ XPathExecutionContextDefault.cpp  4 Dec 2002 21:45:40 -0000       1.55
  @@ -109,7 +109,8 @@
        m_prefixResolver(thePrefixResolver),
        m_throwFoundIndex(false),
        m_nodeListCache(eNodeListCacheListSize),
  -     m_stringCache()
  +     m_stringCache(),
  +     m_cachedPosition()
   {
   }
   
  @@ -167,6 +168,8 @@
        m_nodeListCache.reset(),
   
        m_stringCache.reset();
  +
  +     m_cachedPosition.clear();
   }
   
   
  @@ -221,9 +224,14 @@
   
   
   void 
  -XPathExecutionContextDefault::setContextNodeList(const NodeRefListBase&      
theList)
  +XPathExecutionContextDefault::setContextNodeList(const NodeRefListBase&      
        theList)
   {
  -     m_contextNodeList = &theList;
  +     if (&theList != m_contextNodeList)
  +     {
  +             m_contextNodeList = &theList;
  +
  +             m_cachedPosition.clear();
  +     }
   }
   
   
  @@ -249,11 +257,27 @@
                throw FoundIndex();
        }
   
  -     // Get the index of the node...
  -     const size_type         theIndex = 
m_contextNodeList->indexOf(&contextNode);
  +     if (m_cachedPosition.m_node == &contextNode)
  +     {
  +             assert((m_cachedPosition.m_index == 0 && 
m_contextNodeList->indexOf(&contextNode) == NodeRefListBase::npos) ||
  +                             (m_contextNodeList->indexOf(&contextNode) + 1 
== m_cachedPosition.m_index));
  +     }
  +     else
  +     {
  +             // Get the index of the node...
  +             const size_type         theIndex = 
m_contextNodeList->indexOf(&contextNode);
  +
  +             // If not found, it's 0.  Otherwise, it's the index + 1
  +#if defined(XALAN_NO_MUTABLE)
  +             (XPathExecutionContextDefault*(this))->m_cachedPosition.m_index 
= theIndex == NodeRefListBase::npos ? 0 : theIndex + 1;
  +             (XPathExecutionContextDefault*(this))->m_cachedPosition.m_node 
= &contextNode;
  +#else
  +             m_cachedPosition.m_index = theIndex == NodeRefListBase::npos ? 
0 : theIndex + 1;
  +             m_cachedPosition.m_node = &contextNode;
  +#endif
  +     }
   
  -     // If not found return 0.  Otherwise, return the index + 1
  -     return theIndex == NodeRefListBase::npos ? 0 : theIndex + 1;
  +     return m_cachedPosition.m_index;
   }
   
   
  
  
  
  1.47      +33 -9     xml-xalan/c/src/XPath/XPathExecutionContextDefault.hpp
  
  Index: XPathExecutionContextDefault.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContextDefault.hpp,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- XPathExecutionContextDefault.hpp  21 Nov 2002 01:26:18 -0000      1.46
  +++ XPathExecutionContextDefault.hpp  4 Dec 2002 21:45:40 -0000       1.47
  @@ -353,23 +353,47 @@
   
        enum { eNodeListCacheListSize = 50 };
   
  -     XPathEnvSupport*                        m_xpathEnvSupport;
  +     struct ContextNodeListPositionCache
  +     {
  +             ContextNodeListPositionCache() :
  +                     m_node(0),
  +                     m_index(0)
  +             {
  +             }
   
  -     DOMSupport*                                     m_domSupport;
  +             void
  +             clear()
  +             {
  +                     if (m_node != 0)
  +                     {
  +                             m_node = 0;
  +                     }
  +             }
   
  -     XalanNode*                                      m_currentNode;
  +             const XalanNode*        m_node;
   
  -     const NodeRefListBase*          m_contextNodeList;
  +             size_type                       m_index;
  +     };
   
  -     const PrefixResolver*           m_prefixResolver;
  +     XPathEnvSupport*                                                
m_xpathEnvSupport;
   
  -     bool                                            m_throwFoundIndex;
  +     DOMSupport*                                                             
m_domSupport;
   
  -     XalanDOMString                          m_currentPattern;
  +     XalanNode*                                                              
m_currentNode;
   
  -     NodeListCacheType                       m_nodeListCache;
  +     const NodeRefListBase*                                  
m_contextNodeList;
   
  -     XalanDOMStringCache                     m_stringCache;
  +     const PrefixResolver*                                   
m_prefixResolver;
  +
  +     bool                                                                    
m_throwFoundIndex;
  +
  +     XalanDOMString                                                  
m_currentPattern;
  +
  +     NodeListCacheType                                               
m_nodeListCache;
  +
  +     XalanDOMStringCache                                             
m_stringCache;
  +
  +     mutable ContextNodeListPositionCache    m_cachedPosition;
   
        static const NodeRefList        s_dummyList;
   };
  
  
  

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

Reply via email to