dbertoni    2002/07/10 17:29:11

  Modified:    c/src/XPath XPath.cpp XPath.hpp
  Log:
  New overload for getMatchScore() and new optimization for positional 
predicates in match patterns.
  
  Revision  Changes    Path
  1.72      +79 -23    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.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- XPath.cpp 27 Jun 2002 06:16:04 -0000      1.71
  +++ XPath.cpp 11 Jul 2002 00:29:11 -0000      1.72
  @@ -328,7 +328,6 @@
   XPath::eMatchScore
   XPath::getMatchScore(
                        XalanNode*                              node,
  -                     const PrefixResolver&   resolver,
                        XPathExecutionContext&  executionContext) const
   {
        eMatchScore             score = eMatchScoreNone;
  @@ -344,26 +343,37 @@
        {
                assert(node != 0);
   
  -             const PrefixResolver* const             theCurrentResolver =
  -                     executionContext.getPrefixResolver();
  +             doGetMatchScore(node, executionContext, score);
  +     }
   
  -             if (theCurrentResolver == &resolver)
  -             {
  -                     doGetMatchScore(node, executionContext, score);
  -             }
  -             else
  -             {
  -                     // Push and pop the PrefixResolver...
  -                     XPathExecutionContext::PrefixResolverSetAndRestore      
theSetAndRestore(
  -                                                                             
executionContext,
  -                                                                             
theCurrentResolver,
  -                                                                             
&resolver);
  +     return score;
  +}
   
  -                     doGetMatchScore(node, executionContext, score);
  -             }
  +
  +
  +XPath::eMatchScore
  +XPath::getMatchScore(
  +                     XalanNode*                              node,
  +                     const PrefixResolver&   resolver,
  +                     XPathExecutionContext&  executionContext) const
  +{
  +     const PrefixResolver* const             theCurrentResolver =
  +             executionContext.getPrefixResolver();
  +
  +     if (theCurrentResolver == &resolver)
  +     {
  +             return getMatchScore(node, executionContext);
  +     }
  +     else
  +     {
  +             // Push and pop the PrefixResolver...
  +             XPathExecutionContext::PrefixResolverSetAndRestore      
theSetAndRestore(
  +                                                                     
executionContext,
  +                                                                     
theCurrentResolver,
  +                                                                     
&resolver);
  +
  +             return getMatchScore(node, executionContext);
        }
  -     
  -     return score;
   }
   
   
  @@ -1001,8 +1011,6 @@
                        int                                             opPos,
                        XPathExecutionContext&  executionContext) const
   {
  -     assert(executionContext.getPrefixResolver() != 0);
  -
        const XObject&  ns = 
m_expression.m_tokenQueue[m_expression.m_opMap[opPos + 2]];
   
        const XObject&  varName = 
m_expression.m_tokenQueue[m_expression.m_opMap[opPos + 3]];
  @@ -1686,10 +1694,22 @@
                        {
                                // This is a quick hack to look ahead and see 
if we have
                                // number literal as the predicate, i.e. 
match="foo[1]".
  -                             if (m_expression.getOpCodeMapValue(opPos + 2) 
== XPathExpression::eOP_NUMBERLIT,
  -                                     
XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
  +                             if 
(XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
                                {
  -                                     score = 
handleFoundIndex(executionContext, context, startOpPos);
  +                                     if 
(m_expression.getOpCodeMapValue(opPos + 2) == XPathExpression::eOP_NUMBERLIT)
  +                                     {
  +                                             score = 
handleFoundIndexPositional(
  +                                                     executionContext,
  +                                                     context,
  +                                                     startOpPos);
  +                                     }
  +                                     else
  +                                     {
  +                                             score = handleFoundIndex(
  +                                                     executionContext,
  +                                                     context,
  +                                                     startOpPos);
  +                                     }
                                }
                                else
                                {
  @@ -1765,6 +1785,42 @@
                }
                else
                {
  +                     return eMatchScoreOther;
  +             }
  +     }
  +}
  +
  +
  +
  +XPath::eMatchScore
  +XPath::handleFoundIndexPositional(
  +                     XPathExecutionContext&  executionContext,
  +                     XalanNode*                              localContext,
  +                     int                                     startOpPos) 
const
  +{
  +     XalanNode* const        parentContext =
  +                             DOMServices::getParentOfNode(*localContext);
  +
  +     if (parentContext == 0)
  +     {
  +             return eMatchScoreNone;
  +     }
  +     else
  +     {
  +             typedef XPathExecutionContext::BorrowReturnMutableNodeRefList   
BorrowReturnMutableNodeRefList;
  +
  +             BorrowReturnMutableNodeRefList  mnl(executionContext);
  +
  +             step(executionContext, parentContext, startOpPos, *mnl);
  +
  +             if (mnl->empty() == true)
  +             {
  +                     return eMatchScoreNone;
  +             }
  +             else
  +             {
  +                     assert(mnl->getLength() == 1 && mnl->item(0) == 
localContext);
  +
                        return eMatchScoreOther;
                }
        }
  
  
  
  1.32      +18 -0     xml-xalan/c/src/XPath/XPath.hpp
  
  Index: XPath.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.hpp,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- XPath.hpp 26 Jun 2002 01:20:01 -0000      1.31
  +++ XPath.hpp 11 Jul 2002 00:29:11 -0000      1.32
  @@ -335,6 +335,18 @@
         * Get the match score for the specified node.
         *
         * @param node The node for the score
  +      * @param executionContext current execution context
  +      * @return union of node-set operands
  +      */
  +     eMatchScore
  +     getMatchScore(
  +                     XalanNode*                              node,
  +                     XPathExecutionContext&  executionContext) const;
  +
  +     /**
  +      * Get the match score for the specified node.
  +      *
  +      * @param node The node for the score
         * @param resolver The prefix resolver
         * @param executionContext current execution context
         * @return union of node-set operands
  @@ -1176,6 +1188,12 @@
   
        eMatchScore
        handleFoundIndex(
  +                     XPathExecutionContext&  executionContext,
  +                     XalanNode*                              localContext,
  +                     int                                     startOpPos) 
const;
  +
  +     eMatchScore
  +     handleFoundIndexPositional(
                        XPathExecutionContext&  executionContext,
                        XalanNode*                              localContext,
                        int                                     startOpPos) 
const;
  
  
  

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

Reply via email to