xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From il...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xpath/axes LocPathIterator.java NodeSequence.java
Date Wed, 30 Oct 2002 21:21:06 GMT
ilene       2002/10/30 13:21:06

  Modified:    java/src/org/apache/xpath/axes LocPathIterator.java
                        NodeSequence.java
  Log:
  Patch for bugzilla #13501.
  
  Length wasn't being properly cached in NodeSequence or LocPathIterator.  
  Also the predicate count on the clone wasn't being set properly in LocPathIterator.getLength().
  
  Revision  Changes    Path
  1.36      +20 -6     xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java
  
  Index: LocPathIterator.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- LocPathIterator.java	27 Jun 2002 14:50:54 -0000	1.35
  +++ LocPathIterator.java	30 Oct 2002 21:21:06 -0000	1.36
  @@ -554,15 +554,26 @@
      */
     public int getLength()
     {      
  +    // Tell if this is being called from within a predicate.
     	boolean isPredicateTest = (this == m_execContext.getSubContextList());
  +
  +    // And get how many total predicates are part of this step.
     	int predCount = getPredicateCount();
     	
  -  	if(-1 != m_length && !isPredicateTest)
  +    // If we have already calculated the length, and the current predicate 
  +    // is the first predicate, then return the length.  We don't cache 
  +    // the anything but the length of the list to the first predicate.
  +    if (-1 != m_length && isPredicateTest && m_predicateIndex < 1)
     		return m_length;
     	
  -  	if(m_foundLast)
  +    // I'm a bit worried about this one, since it doesn't have the 
  +    // checks found above.  I suspect it's fine.  -sb
  +    if (m_foundLast)
     		return m_pos;
     		
  +    // Create a clone, and count from the current position to the end 
  +    // of the list, not taking into account the current predicate and 
  +    // predicates after the current one.
       int pos = (m_predicateIndex >= 0) ? getProximityPosition() : m_pos;
                 
       LocPathIterator clone;
  @@ -579,10 +590,13 @@
       // We want to clip off the last predicate, but only if we are a sub 
       // context node list, NOT if we are a context list.  See pos68 test, 
       // also test against bug4638.
  -    if(predCount > 0 && isPredicateTest)
  +    if (predCount > 0 && isPredicateTest)
       {
         // Don't call setPredicateCount, because it clones and is slower.
  -      clone.m_predCount = predCount - 1;
  +      clone.m_predCount = m_predicateIndex;
  +      // The line above used to be:
  +      // clone.m_predCount = predCount - 1;
  +      // ...which looks like a dumb bug to me. -sb
       }
   
       int next;
  @@ -592,7 +606,7 @@
         pos++;
       }
       
  -    if(!isPredicateTest)
  +    if (isPredicateTest && m_predicateIndex < 1)
         m_length = pos;
       
       return pos;
  @@ -1063,5 +1077,5 @@
     {
       return getLength();
     }
  -
  +
   }
  
  
  
  1.5       +8 -3      xml-xalan/java/src/org/apache/xpath/axes/NodeSequence.java
  
  Index: NodeSequence.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/NodeSequence.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NodeSequence.java	22 Oct 2002 15:42:36 -0000	1.4
  +++ NodeSequence.java	30 Oct 2002 21:21:06 -0000	1.5
  @@ -535,9 +535,14 @@
     {
     	if(hasCache())
     	{
  -        if (m_obj instanceof NodeSetDTM) {
  -            return ((NodeSetDTM)m_obj).getLength();
  +        // If this NodeSequence wraps a mutable nodeset, then
  +        // m_last will not reflect the size of the nodeset if
  +        // it has been mutated...
  +        if (m_iter instanceof NodeSetDTM)
  +        {
  +            return m_iter.getLength();
           }    
  +        
   	  	if(-1 == m_last)
   	  	{
   	  		int pos = m_next;
  @@ -548,7 +553,7 @@
     	}
     	else
     	{
  -  		return m_iter.getLength();
  +  		return (-1 == m_last) ? (m_last = m_iter.getLength()) : m_last;
     	}
     }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message