xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From santiag...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom CurrentNodeListIterator.java
Date Thu, 13 Jun 2002 12:26:16 GMT
santiagopg    2002/06/13 05:26:16

  Modified:    java/src/org/apache/xalan/xsltc/dom
                        CurrentNodeListIterator.java
  Log:
  Replaced eager by lazy computation of last.
  
  Revision  Changes    Path
  1.8       +32 -28    xml-xalan/java/src/org/apache/xalan/xsltc/dom/CurrentNodeListIterator.java
  
  Index: CurrentNodeListIterator.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/CurrentNodeListIterator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CurrentNodeListIterator.java	24 Apr 2002 17:03:16 -0000	1.7
  +++ CurrentNodeListIterator.java	13 Jun 2002 12:26:16 -0000	1.8
  @@ -70,28 +70,31 @@
   import org.apache.xalan.xsltc.runtime.BasisLibrary;
   
   public final class CurrentNodeListIterator extends NodeIteratorBase {
  -    private NodeIterator _source;
  +
       private boolean _docOrder;
  +    private NodeIterator _source;
       private final CurrentNodeListFilter _filter;
       private IntegerArray _nodes = new IntegerArray();
   	
       private int _current;	// index in _nodes of the next node to try
  +    private int _last = -1;		
   	
  -    private AbstractTranslet _translet;
       private final int _currentNode;
  -    private int _last;		
  +    private AbstractTranslet _translet;
   
       public CurrentNodeListIterator(NodeIterator source, 
   				   CurrentNodeListFilter filter,
   				   int currentNode,
  -				   AbstractTranslet translet) {
  +				   AbstractTranslet translet) 
  +    {
   	this(source, !source.isReverse(), filter, currentNode, translet);
       }
   
       public CurrentNodeListIterator(NodeIterator source, boolean docOrder,
   				   CurrentNodeListFilter filter,
   				   int currentNode,
  -				   AbstractTranslet translet) {
  +				   AbstractTranslet translet) 
  +    {
   	_source = source;
   	_filter = filter;
   	_translet = translet;
  @@ -129,13 +132,13 @@
       }
   
       public int next() {
  -	final boolean docOrder = _docOrder;
   	final int last = _nodes.cardinality();
   	final int currentNode = _currentNode;
  +	final AbstractTranslet translet = _translet;
   
   	for (int index = _current; index < last; ) {
   	    final int node = _nodes.at(index++); 	// note increment
  -	    if (_filter.test(node, index, last, currentNode, _translet, this)) {
  +	    if (_filter.test(node, index, last, currentNode, translet, this)) {
   		_current = index;
   		return returnNode(node);
   	    }
  @@ -143,28 +146,12 @@
   	return END;
       }
   
  -    private int computePositionOfLast() {
  -	int lastPosition = 0;
  -	final boolean docOrder = _docOrder;
  -        final int last = _nodes.cardinality();
  -        final int currNode = _currentNode;
  -
  -	for (int index = _current; index < last; ) {
  -            int nodeIndex = _nodes.at(index++); 	// note increment
  -            if (_filter.test(nodeIndex, index, last, currNode, _translet, this)) {
  -                lastPosition++;
  -            }
  -        }
  -	return lastPosition;
  -    }
  -
       public NodeIterator setStartNode(int node) {
   	NodeIterator retval = this;
   	
   	if (_isRestartable) {
  -	    // iterator is not a clone
   	    _source.setStartNode(_startNode = node);
  -	    // including ROOT
  +
   	    _nodes.clear();
   	    while ((node = _source.next()) != END) {
   		_nodes.add(node);
  @@ -172,13 +159,14 @@
   	    _current = 0;
   	    retval = resetPosition();
   	}
  -	// compute position of _last
  -  	_last = computePositionOfLast();	
   	return retval;
       }
   	
       public int getLast() {
  -	return (_last == -1) ? computePositionOfLast() : _last;
  +	if (_last == -1) {
  +	    _last = computePositionOfLast();
  +	}
  +	return _last;
       }
   
       public void setMark() {
  @@ -190,4 +178,20 @@
   	_source.gotoMark();
   	_current = _markedNode;
       }
  +
  +    private int computePositionOfLast() {
  +        final int last = _nodes.cardinality();
  +        final int currNode = _currentNode;
  +	final AbstractTranslet translet = _translet;
  +
  +	int lastPosition = 0;
  +	for (int index = _current; index < last; ) {
  +            int nodeIndex = _nodes.at(index++); 	// note increment
  +            if (_filter.test(nodeIndex, index, last, currNode, translet, this)) {
  +                lastPosition++;
  +            }
  +        }
  +	return lastPosition;
  +    }
   }
  +
  
  
  

---------------------------------------------------------------------
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