You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by il...@apache.org on 2002/10/07 20:16:15 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath XPathContext.java

ilene       2002/10/07 11:16:15

  Modified:    java/src/org/apache/xml/utils IntStack.java IntVector.java
                        ObjectVector.java
               java/src/org/apache/xalan/templates ElemApplyTemplates.java
                        ElemForEach.java
               java/src/org/apache/xalan/transformer TransformerImpl.java
                        TransformSnapshotImpl.java StackGuard.java
               java/src/org/apache/xpath XPathContext.java
  Added:       java/src/org/apache/xml/utils ObjectStack.java
  Log:
  Commiting Gordon Chiu's (grchiu@ca.ibm.com) patch for bugzilla#8175.
  
  IntStack's and ObjectStack's are now used in place of fixed length arrays, so that users
  should not run into limitations based on array sizes.  The initial size of the arrays has
  been set to current array sizes, so the user's experience should not change much, except
  in the cases where they were running into the size limitation.
  
  No performance analysis has been done to determine an optimal initial
  size for the stacks.
  
  Revision  Changes    Path
  1.7       +21 -0     xml-xalan/java/src/org/apache/xml/utils/IntStack.java
  
  Index: IntStack.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/IntStack.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IntStack.java	4 Mar 2002 18:47:44 -0000	1.6
  +++ IntStack.java	7 Oct 2002 18:16:14 -0000	1.7
  @@ -88,6 +88,16 @@
     {
       super(blocksize);
     }
  +  
  +  /**
  +   * Copy constructor for IntStack
  +   * 
  +   * @param v IntStack to copy
  +   */
  +  public IntStack (IntStack v)
  +  {
  +  	super(v);
  +  }
   
     /**
      * Pushes an item onto the top of this stack.
  @@ -222,5 +232,16 @@
       }
   
       return -1;
  +  }
  +  
  +  /**
  +   * Returns clone of current IntStack
  +   * 
  +   * @return clone of current IntStack
  +   */
  +  public Object clone()
  +    throws CloneNotSupportedException
  +  {
  +  	return (IntStack) super.clone();
     }
   }
  
  
  
  1.5       +26 -1     xml-xalan/java/src/org/apache/xml/utils/IntVector.java
  
  Index: IntVector.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/IntVector.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IntVector.java	21 Jun 2001 18:52:53 -0000	1.4
  +++ IntVector.java	7 Oct 2002 18:16:14 -0000	1.5
  @@ -66,7 +66,7 @@
    * access to existing nodes is O(1) fast but appending may be O(N**2)
    * slow. See also SuballocatedIntVector.
    */
  -public class IntVector
  +public class IntVector implements Cloneable
   {
   
     /** Size of blocks to allocate          */
  @@ -119,6 +119,19 @@
       m_map = new int[blocksize];
     }
   
  +  /**
  +   * Copy constructor for IntVector
  +   * 
  +   * @param v Existing IntVector to copy
  +   */
  +  public IntVector(IntVector v)
  +  {
  +  	m_map = new int[v.m_mapSize];
  +    m_mapSize = v.m_mapSize;
  +    m_firstFree = v.m_firstFree;
  +  	m_blocksize = v.m_blocksize;
  +  	System.arraycopy(v.m_map, 0, m_map, 0, m_firstFree);
  +  }
   
     /**
      * Get the length of the list.
  @@ -427,4 +440,16 @@
   
       return java.lang.Integer.MIN_VALUE;
     }
  +  
  +  /**
  +   * Returns clone of current IntVector
  +   * 
  +   * @return clone of current IntVector
  +   */
  +  public Object clone()
  +    throws CloneNotSupportedException
  +  {
  +  	return new IntVector(this);
  +  }
  +  
   }
  
  
  
  1.2       +25 -1     xml-xalan/java/src/org/apache/xml/utils/ObjectVector.java
  
  Index: ObjectVector.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/ObjectVector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectVector.java	7 Oct 2002 15:30:02 -0000	1.1
  +++ ObjectVector.java	7 Oct 2002 18:16:14 -0000	1.2
  @@ -66,7 +66,7 @@
    * access to existing nodes is O(1) fast but appending may be O(N**2)
    * slow. 
    */
  -public class ObjectVector
  +public class ObjectVector implements Cloneable
   {
   
     /** Size of blocks to allocate          */
  @@ -119,6 +119,19 @@
       m_map = new Object[blocksize];
     }
   
  +  /**
  +   * Copy constructor for ObjectVector
  +   * 
  +   * @param v Existing ObjectVector to copy
  +   */
  +  public ObjectVector(ObjectVector v)
  +  {
  +  	m_map = new Object[v.m_mapSize];
  +    m_mapSize = v.m_mapSize;
  +    m_firstFree = v.m_firstFree;
  +  	m_blocksize = v.m_blocksize;
  +  	System.arraycopy(v.m_map, 0, m_map, 0, m_firstFree);
  +  }
   
     /**
      * Get the length of the list.
  @@ -440,4 +453,15 @@
       m_map = newMap;
       
     }  
  +  
  +  /**
  +   * Returns clone of current ObjectVector
  +   * 
  +   * @return clone of current ObjectVector
  +   */
  +  public Object clone()
  +    throws CloneNotSupportedException
  +  {
  +  	return new ObjectVector(this);
  +  }
   }
  
  
  
  1.1                  xml-xalan/java/src/org/apache/xml/utils/ObjectStack.java
  
  Index: ObjectStack.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xml.utils;
  
  import java.util.EmptyStackException;
  
  /**
   * <meta name="usage" content="internal"/>
   * Implement a stack of simple integers.
   *
   * %OPT%
   * This is currently based on ObjectVector, which permits fast acess but pays a
   * heavy recopying penalty if/when its size is increased. If we expect deep
   * stacks, we should consider a version based on ChunkedObjectVector.
   */
  public class ObjectStack extends ObjectVector
  {
  
    /**
     * Default constructor.  Note that the default
     * block size is very small, for small lists.
     */
    public ObjectStack()
    {
      super();
    }
  
    /**
     * Construct a ObjectVector, using the given block size.
     *
     * @param blocksize Size of block to allocate
     */
    public ObjectStack(int blocksize)
    {
      super(blocksize);
    }
  
    /**
     * Copy constructor for ObjectStack
     * 
     * @param v ObjectStack to copy
     */
    public ObjectStack (ObjectStack v)
    {
    	super(v);
    }
    
    /**
     * Pushes an item onto the top of this stack.
     *
     * @param   i   the int to be pushed onto this stack.
     * @return  the <code>item</code> argument.
     */
    public Object push(Object i)
    {
  
      if ((m_firstFree + 1) >= m_mapSize)
      {
        m_mapSize += m_blocksize;
  
        Object newMap[] = new Object[m_mapSize];
  
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
  
        m_map = newMap;
      }
  
      m_map[m_firstFree] = i;
  
      m_firstFree++;
  
      return i;
    }
  
    /**
     * Removes the object at the top of this stack and returns that
     * object as the value of this function.
     *
     * @return     The object at the top of this stack.
     */
    public Object pop()
    {
      Object val = m_map[--m_firstFree];
      m_map[m_firstFree] = null;
      
      return val;
    }
  
    /**
     * Quickly pops a number of items from the stack.
     */
  
    public void quickPop(int n)
    {
      m_firstFree -= n;
    }
  
    /**
     * Looks at the object at the top of this stack without removing it
     * from the stack.
     *
     * @return     the object at the top of this stack.
     * @throws  EmptyStackException  if this stack is empty.
     */
    public Object peek()
    {
      try {
        return m_map[m_firstFree - 1];
      }
      catch (ArrayIndexOutOfBoundsException e)
      {
        throw new EmptyStackException();
      }
    }
  
    /**
     * Looks at the object at the position the stack counting down n items.
     *
     * @param n The number of items down, indexed from zero.
     * @return     the object at n items down.
     * @throws  EmptyStackException  if this stack is empty.
     */
    public Object peek(int n)
    {
      try {
        return m_map[m_firstFree-(1+n)];
      }
      catch (ArrayIndexOutOfBoundsException e)
      {
        throw new EmptyStackException();
      }
    }
  
    /**
     * Sets an object at a the top of the statck
     *
     *
     * @param val object to set at the top
     * @throws  EmptyStackException  if this stack is empty.
     */
    public void setTop(Object val)
    {
      try {
        m_map[m_firstFree - 1] = val;
      }
      catch (ArrayIndexOutOfBoundsException e)
      {
        throw new EmptyStackException();
      }
    }
  
    /**
     * Tests if this stack is empty.
     *
     * @return  <code>true</code> if this stack is empty;
     *          <code>false</code> otherwise.
     * @since   JDK1.0
     */
    public boolean empty()
    {
      return m_firstFree == 0;
    }
  
    /**
     * Returns where an object is on this stack.
     *
     * @param   o   the desired object.
     * @return  the distance from the top of the stack where the object is]
     *          located; the return value <code>-1</code> indicates that the
     *          object is not on the stack.
     * @since   JDK1.0
     */
    public int search(Object o)
    {
  
      int i = lastIndexOf(o);
  
      if (i >= 0)
      {
        return size() - i;
      }
  
      return -1;
    }
  
    /**
     * Returns clone of current ObjectStack
     * 
     * @return clone of current ObjectStack
     */
    public Object clone()
      throws CloneNotSupportedException
    {
    	return (ObjectStack) super.clone();
    }  
    
  }
  
  
  
  1.26      +5 -6      xml-xalan/java/src/org/apache/xalan/templates/ElemApplyTemplates.java
  
  Index: ElemApplyTemplates.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemApplyTemplates.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ElemApplyTemplates.java	24 Jul 2002 17:06:46 -0000	1.25
  +++ ElemApplyTemplates.java	7 Oct 2002 18:16:15 -0000	1.26
  @@ -72,6 +72,7 @@
   import org.apache.xpath.objects.XObject;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
  +import org.apache.xml.utils.IntStack;
   
   /**
    * <meta name="usage" content="advanced"/>
  @@ -296,12 +297,10 @@
         }
         
         xctxt.pushCurrentNode(DTM.NULL);
  -      int[] currentNodes = xctxt.getCurrentNodeStack();
  -      int currentNodePos = xctxt.getCurrentNodeFirstFree() - 1;
  +      IntStack currentNodes = xctxt.getCurrentNodeStack();
         
         xctxt.pushCurrentExpressionNode(DTM.NULL);
  -      int[] currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();
  -      int currentExpressionNodePos = xctxt.getCurrentExpressionNodesFirstFree() - 1;
  +      IntStack currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();     
   
         xctxt.pushSAXLocatorNull();
         xctxt.pushContextNodeList(sourceNodes);
  @@ -311,8 +310,8 @@
         int child;
         while (DTM.NULL != (child = sourceNodes.nextNode()))
         {
  -        currentNodes[currentNodePos] = child;
  -        currentExpressionNodes[currentExpressionNodePos] = child;
  +        currentNodes.setTop(child);
  +        currentExpressionNodes.setTop(child);
   
           if(xctxt.getDTM(child) != dtm)
           {
  
  
  
  1.30      +5 -7      xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java
  
  Index: ElemForEach.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- ElemForEach.java	24 Jul 2002 17:06:46 -0000	1.29
  +++ ElemForEach.java	7 Oct 2002 18:16:15 -0000	1.30
  @@ -75,6 +75,7 @@
   import java.util.Vector;
   
   import org.apache.xml.utils.QName;
  +import org.apache.xml.utils.IntStack;
   import org.apache.xml.utils.PrefixResolver;
   import org.apache.xalan.res.XSLTErrorResources;
   import org.apache.xalan.transformer.TransformerImpl;
  @@ -393,14 +394,11 @@
   
         xctxt.pushCurrentNode(DTM.NULL);
   
  -      int[] currentNodes = xctxt.getCurrentNodeStack();
  -      int currentNodePos = xctxt.getCurrentNodeFirstFree() - 1;
  +      IntStack currentNodes = xctxt.getCurrentNodeStack();
   
         xctxt.pushCurrentExpressionNode(DTM.NULL);
   
  -      int[] currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();
  -      int currentExpressionNodePos =
  -              xctxt.getCurrentExpressionNodesFirstFree() - 1;
  +      IntStack currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();
   
         xctxt.pushSAXLocatorNull();
         xctxt.pushContextNodeList(sourceNodes);
  @@ -414,8 +412,8 @@
   
         while (DTM.NULL != (child = sourceNodes.nextNode()))
         {
  -        currentNodes[currentNodePos] = child;
  -        currentExpressionNodes[currentExpressionNodePos] = child;
  +        currentNodes.setTop(child);
  +        currentExpressionNodes.setTop(child);
   
           if ((child & DTMManager.IDENT_DTM_DEFAULT) != docID)
           {
  
  
  
  1.135     +20 -25    xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
  retrieving revision 1.134
  retrieving revision 1.135
  diff -u -r1.134 -r1.135
  --- TransformerImpl.java	13 Sep 2002 17:50:24 -0000	1.134
  +++ TransformerImpl.java	7 Oct 2002 18:16:15 -0000	1.135
  @@ -110,6 +110,7 @@
   import org.apache.xml.utils.DOMBuilder;
   import org.apache.xml.utils.NodeVector;
   import org.apache.xml.utils.ObjectPool;
  +import org.apache.xml.utils.ObjectStack;
   import org.apache.xml.utils.QName;
   import org.apache.xml.utils.SAXSourceLocator;
   import org.apache.xml.utils.WrappedRuntimeException;
  @@ -238,11 +239,11 @@
      * so a tool can discover the calling template. Note the use of an array 
      * for this limits the recursion depth to 4K.
      */
  -  ElemTemplateElement[] m_currentTemplateElements 
  -      = new ElemTemplateElement[XPathContext.RECURSIONLIMIT];
  +  ObjectStack m_currentTemplateElements 
  +      = new ObjectStack(XPathContext.RECURSIONLIMIT);
     
     /** The top of the currentTemplateElements stack. */
  -  int m_currentTemplateElementsTop = 0;
  +  //int m_currentTemplateElementsTop = 0;
   
     /**
      * A node vector used as a stack to track the current
  @@ -496,13 +497,7 @@
         resetUserParameters();
         
   
  -      int n = m_currentTemplateElements.length;
  -      for (int i = 0; i < n; i++) 
  -      {
  -        m_currentTemplateElements[i] = null;
  -      }
  -      m_currentTemplateElementsTop = 0;
  -      
  +      m_currentTemplateElements.removeAllElements();     
         m_currentMatchTemplates.removeAllElements();
         m_currentMatchedNodes.removeAllElements();
         
  @@ -2313,8 +2308,8 @@
   
       XPathContext xctxt = m_xcontext;
       xctxt.pushSAXLocatorNull();
  -    int currentTemplateElementsTop = m_currentTemplateElementsTop;
  -    m_currentTemplateElementsTop++;
  +    int currentTemplateElementsTop = m_currentTemplateElements.size();
  +    m_currentTemplateElements.push(null);
   
       try
       {
  @@ -2327,7 +2322,7 @@
             continue;
   
           xctxt.setSAXLocator(t);
  -        m_currentTemplateElements[currentTemplateElementsTop] = t;
  +        m_currentTemplateElements.setElementAt(t,currentTemplateElementsTop);
           t.execute(this);
         }
       }
  @@ -2339,7 +2334,7 @@
       }
       finally
       {
  -      m_currentTemplateElementsTop--;
  +      m_currentTemplateElements.pop();
         xctxt.popSAXLocator();
       }
   
  @@ -2459,10 +2454,10 @@
     public Vector getElementCallstack()
     {
     	Vector elems = new Vector();
  -  	int nStackSize = m_currentTemplateElementsTop;
  +  	int nStackSize = m_currentTemplateElements.size();
     	for(int i = 0; i < nStackSize; i++)
     	{
  -  		ElemTemplateElement elem = m_currentTemplateElements[i];
  +  		ElemTemplateElement elem = (ElemTemplateElement) m_currentTemplateElements.elementAt(i);
     		if(null != elem)
     		{
     			elems.addElement(elem);
  @@ -2479,7 +2474,7 @@
      */
     public int getCurrentTemplateElementsCount()
     {
  -  	return m_currentTemplateElementsTop;
  +  	return m_currentTemplateElements.size();
     }
     
     
  @@ -2489,7 +2484,7 @@
      * @return The number of active elements on 
      * the currentTemplateElements stack.
      */
  -  public ElemTemplateElement[] getCurrentTemplateElements()
  +  public ObjectStack getCurrentTemplateElements()
     {
     	return m_currentTemplateElements;
     }
  @@ -2502,7 +2497,7 @@
      */
     public void pushElemTemplateElement(ElemTemplateElement elem)
     {
  -    m_currentTemplateElements[m_currentTemplateElementsTop++] = elem;
  +    m_currentTemplateElements.push(elem);
     }
   
     /**
  @@ -2510,7 +2505,7 @@
      */
     public void popElemTemplateElement()
     {
  -    m_currentTemplateElementsTop--;
  +    m_currentTemplateElements.pop();
     }
   
     /**
  @@ -2522,7 +2517,7 @@
      */
     public void setCurrentElement(ElemTemplateElement e)
     {
  -    m_currentTemplateElements[m_currentTemplateElementsTop-1] = e;
  +    m_currentTemplateElements.setTop(e);
     }
   
     /**
  @@ -2534,8 +2529,8 @@
      */
     public ElemTemplateElement getCurrentElement()
     {
  -    return (m_currentTemplateElementsTop > 0) ? 
  -        m_currentTemplateElements[m_currentTemplateElementsTop-1] : null;
  +    return (m_currentTemplateElements.size() > 0) ? 
  +        (ElemTemplateElement) m_currentTemplateElements.peek() : null;
     }
   
     /**
  @@ -2559,10 +2554,10 @@
     public Vector getTemplateCallstack()
     {
     	Vector elems = new Vector();
  -  	int nStackSize = m_currentTemplateElementsTop;
  +  	int nStackSize = m_currentTemplateElements.size();
     	for(int i = 0; i < nStackSize; i++)
     	{
  -  		ElemTemplateElement elem = m_currentTemplateElements[i];
  +  		ElemTemplateElement elem = (ElemTemplateElement) m_currentTemplateElements.elementAt(i);
     		if(null != elem && (elem.getXSLToken() != Constants.ELEMNAME_TEMPLATE))
     		{
     			elems.addElement(elem);
  
  
  
  1.7       +12 -9     xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshotImpl.java
  
  Index: TransformSnapshotImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshotImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TransformSnapshotImpl.java	3 Aug 2001 17:06:05 -0000	1.6
  +++ TransformSnapshotImpl.java	7 Oct 2002 18:16:15 -0000	1.7
  @@ -60,14 +60,17 @@
   import org.apache.xpath.VariableStack;
   import org.apache.xpath.axes.ContextNodeList;
   import org.apache.xml.utils.NodeVector;
  +import org.apache.xml.utils.IntStack;
   import org.apache.xml.utils.BoolStack;
   import org.apache.xml.dtm.DTMIterator;
   import org.apache.xalan.templates.ElemTemplateElement;
   
   import java.util.Stack;
   
  +
   import org.xml.sax.helpers.NamespaceSupport;
   import org.apache.xml.utils.NamespaceSupport2;
  +import org.apache.xml.utils.ObjectStack;
   
   import java.util.Enumeration;
   
  @@ -90,10 +93,10 @@
      * The stack of <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a> objects.
      *  Not to be confused with the current node list.  
      */
  -  private int[] m_currentNodes;
  +  private IntStack m_currentNodes;
   
     /** A stack of the current sub-expression nodes. */
  -  private int[] m_currentExpressionNodes;
  +  private IntStack m_currentExpressionNodes;
   
     /**
      * The current context node lists stack.
  @@ -121,7 +124,7 @@
      * org.apache.xalan.transformer.TransformState interface,
      * so a tool can discover the calling template. 
      */
  -  private ElemTemplateElement[] m_currentTemplateElements;
  +  private ObjectStack m_currentTemplateElements;
   
     /**
      * A node vector used as a stack to track the current
  @@ -201,9 +204,9 @@
         XPathContext xpc = transformer.getXPathContext();
   
         m_variableStacks = (VariableStack) xpc.getVarStack().clone();
  -      m_currentNodes = (int[]) xpc.getCurrentNodeStack().clone();
  +      m_currentNodes = (IntStack) xpc.getCurrentNodeStack().clone();
         m_currentExpressionNodes =
  -        (int[]) xpc.getCurrentExpressionNodeStack().clone();
  +        (IntStack) xpc.getCurrentExpressionNodeStack().clone();
         m_contextNodeLists = (Stack) xpc.getContextNodeListsStack().clone();
   
         if (!m_contextNodeLists.empty())
  @@ -214,7 +217,7 @@
         m_currentTemplateRuleIsNull =
           (BoolStack) transformer.m_currentTemplateRuleIsNull.clone();
         m_currentTemplateElements =
  -        (ElemTemplateElement[]) transformer.m_currentTemplateElements.clone();
  +        (ObjectStack) transformer.m_currentTemplateElements.clone();
         m_currentMatchTemplates =
           (Stack) transformer.m_currentMatchTemplates.clone();
         m_currentMatchNodes =
  @@ -269,9 +272,9 @@
         XPathContext xpc = transformer.getXPathContext();
   
         xpc.setVarStack((VariableStack) m_variableStacks.clone());
  -      xpc.setCurrentNodeStack((int[]) m_currentNodes.clone());
  +      xpc.setCurrentNodeStack((IntStack) m_currentNodes.clone());
         xpc.setCurrentExpressionNodeStack(
  -        (int[]) m_currentExpressionNodes.clone());
  +        (IntStack) m_currentExpressionNodes.clone());
         xpc.setContextNodeListsStack((Stack) m_contextNodeLists.clone());
   
         if (m_contextNodeList != null)
  @@ -282,7 +285,7 @@
         transformer.m_currentTemplateRuleIsNull =
           (BoolStack) m_currentTemplateRuleIsNull.clone();
         transformer.m_currentTemplateElements =
  -        (ElemTemplateElement[]) m_currentTemplateElements.clone();
  +        (ObjectStack) m_currentTemplateElements.clone();
         transformer.m_currentMatchTemplates =
           (Stack) m_currentMatchTemplates.clone();
         transformer.m_currentMatchedNodes =
  
  
  
  1.9       +5 -4      xml-xalan/java/src/org/apache/xalan/transformer/StackGuard.java
  
  Index: StackGuard.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/StackGuard.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StackGuard.java	8 Jun 2002 21:23:00 -0000	1.8
  +++ StackGuard.java	7 Oct 2002 18:16:15 -0000	1.9
  @@ -64,6 +64,7 @@
   import org.apache.xalan.templates.Constants;
   import org.apache.xalan.templates.ElemTemplate;
   import org.apache.xalan.templates.ElemTemplateElement;
  +import org.apache.xml.utils.ObjectStack;
   
   /**
    * Class to guard against recursion getting too deep.
  @@ -140,11 +141,11 @@
      */
     public int countLikeTemplates(ElemTemplate templ, int pos)
     {
  -  	ElemTemplateElement[] elems = m_transformer.getCurrentTemplateElements();
  +  	ObjectStack elems = m_transformer.getCurrentTemplateElements();
     	int count = 1;
       for (int i = pos-1; i >= 0; i--)
       {
  -    	if(elems[i] == templ)
  +    	if((ElemTemplateElement)elems.elementAt(i) == templ)
       		count++;
       }
   	
  @@ -161,10 +162,10 @@
      */
     private ElemTemplate getNextMatchOrNamedTemplate(int pos)
     {
  -  	ElemTemplateElement[] elems = m_transformer.getCurrentTemplateElements();
  +  	ObjectStack elems = m_transformer.getCurrentTemplateElements();
       for (int i = pos; i >= 0; i--)
       {
  -    	ElemTemplateElement elem = elems[i];
  +    	ElemTemplateElement elem = (ElemTemplateElement) elems.elementAt(i);
       	if(null != elem)
       	{
   	    	if(elem.getXSLToken() == Constants.ELEMNAME_TEMPLATE)
  
  
  
  1.42      +52 -70    xml-xalan/java/src/org/apache/xpath/XPathContext.java
  
  Index: XPathContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathContext.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- XPathContext.java	27 Sep 2002 13:54:49 -0000	1.41
  +++ XPathContext.java	7 Oct 2002 18:16:15 -0000	1.42
  @@ -67,6 +67,7 @@
   
   // Xalan imports
   import org.apache.xml.utils.IntStack;
  +import org.apache.xml.utils.ObjectStack;
   import org.apache.xml.utils.NSInfo;
   import org.apache.xml.utils.PrefixResolver;
   import org.apache.xml.utils.QName;
  @@ -341,10 +342,10 @@
      */
     public XPathContext()
     {
  -    m_prefixResolvers[m_prefixResolversTop++] = null;
  -    m_currentNodes[m_currentNodesFirstFree++] = DTM.NULL;
  -    m_currentNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
  -    m_saxLocations[m_saxLocationsTop++] = null;
  +    m_prefixResolvers.push(null);
  +    m_currentNodes.push(DTM.NULL);
  +    m_currentExpressionNodes.push(DTM.NULL);
  +    m_saxLocations.push(null);
     }
   
     /**
  @@ -359,10 +360,10 @@
         m_ownerGetErrorListener = m_owner.getClass().getMethod("getErrorListener", new Class[] {});
       }
       catch (NoSuchMethodException nsme) {}
  -    m_prefixResolvers[m_prefixResolversTop++] = null;
  -    m_currentNodes[m_currentNodesFirstFree++] = DTM.NULL;
  -    m_currentNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
  -    m_saxLocations[m_saxLocationsTop++] = null;
  +    m_prefixResolvers.push(null);
  +    m_currentNodes.push(DTM.NULL);
  +    m_currentExpressionNodes.push(DTM.NULL);
  +    m_saxLocations.push(null);
     }
   
     /**
  @@ -385,30 +386,24 @@
       m_dtmManager = DTMManager.newInstance(
                      org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
                      
  -    m_saxLocations = new SourceLocator[RECURSIONLIMIT];
  -	m_saxLocationsTop = 0;
  -    
  +    m_saxLocations.removeAllElements();   
   	m_axesIteratorStack = new Stack();
   	m_contextNodeLists = new Stack();
  -	m_currentExpressionNodes = new int[RECURSIONLIMIT];
  -	m_currentExpressionNodesFirstFree = 0;
  -	m_currentNodes = new int[RECURSIONLIMIT];
  -	m_currentNodesFirstFree = 0;
  +	m_currentExpressionNodes.removeAllElements();
  +	m_currentNodes.removeAllElements();
   	m_iteratorRoots = new NodeVector();
   	m_predicatePos = new IntStack();
   	m_predicateRoots = new NodeVector();
  -	m_prefixResolvers = new PrefixResolver[RECURSIONLIMIT];
  -	int m_prefixResolversTop = 0;
  +	m_prefixResolvers.removeAllElements();
   	
  -	m_prefixResolvers[m_prefixResolversTop++] = null;
  -    m_currentNodes[m_currentNodesFirstFree++] = DTM.NULL;
  -    m_currentNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
  -    m_saxLocations[m_saxLocationsTop++] = null;
  +	m_prefixResolvers.push(null);
  +    m_currentNodes.push(DTM.NULL);
  +    m_currentExpressionNodes.push(DTM.NULL);
  +    m_saxLocations.push(null);
     }
   
     /** The current stylesheet locator. */
  -  SourceLocator[] m_saxLocations = new SourceLocator[RECURSIONLIMIT];
  -  int m_saxLocationsTop = 0;
  +  ObjectStack m_saxLocations = new ObjectStack(RECURSIONLIMIT);
   
     /**
      * Set the current locater in the stylesheet.
  @@ -417,7 +412,7 @@
      */
     public void setSAXLocator(SourceLocator location)
     {
  -    m_saxLocations[m_saxLocationsTop-1] = location;
  +    m_saxLocations.setTop(location);
     }
     
     /**
  @@ -427,7 +422,7 @@
      */
     public void pushSAXLocator(SourceLocator location)
     {
  -    m_saxLocations[m_saxLocationsTop++] = location;
  +    m_saxLocations.push(location);
     }
     
     /**
  @@ -438,7 +433,7 @@
      */
     public void pushSAXLocatorNull()
     {
  -    m_saxLocationsTop++;
  +    m_saxLocations.push(null);
     }
   
   
  @@ -447,7 +442,7 @@
      */
     public void popSAXLocator()
     {
  -    m_saxLocationsTop--;
  +    m_saxLocations.pop();
     }
   
     /**
  @@ -457,7 +452,7 @@
      */
     public SourceLocator getSAXLocator()
     {
  -    return m_saxLocations[m_saxLocationsTop-1];
  +    return (SourceLocator) m_saxLocations.peek();
     }
   
     /** The owner context of this XPathContext.  In the case of XSLT, this will be a
  @@ -733,13 +728,12 @@
      *  Not to be confused with the current node list.  %REVIEW% Note that there 
      *  are no bounds check and resize for this stack, so if it is blown, it's all 
      *  over.  */
  -  private int m_currentNodes[] = new int[RECURSIONLIMIT];
  -  protected int m_currentNodesFirstFree = 0;
  +  private IntStack m_currentNodes = new IntStack(RECURSIONLIMIT);
      
   //  private NodeVector m_currentNodes = new NodeVector();
     
  -  public int[] getCurrentNodeStack() {return m_currentNodes; }
  -  public void setCurrentNodeStack(int[] nv) { m_currentNodes = nv; }
  +  public IntStack getCurrentNodeStack() {return m_currentNodes; }
  +  public void setCurrentNodeStack(IntStack nv) { m_currentNodes = nv; }
   
     /**
      * Get the current context node.
  @@ -748,7 +742,7 @@
      */
     public final int getCurrentNode()
     {
  -    return m_currentNodes[m_currentNodesFirstFree-1];
  +    return m_currentNodes.peek();
     }
     
     /**
  @@ -759,8 +753,8 @@
      */
     public final void pushCurrentNodeAndExpression(int cn, int en)
     {
  -    m_currentNodes[m_currentNodesFirstFree++] = cn;
  -    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = cn;
  +    m_currentNodes.push(cn);
  +    m_currentExpressionNodes.push(cn);
     }
   
     /**
  @@ -768,8 +762,8 @@
      */
     public final void popCurrentNodeAndExpression()
     {
  -    m_currentNodesFirstFree--;
  -    m_currentExpressionNodesFirstFree--;
  +    m_currentNodes.quickPop(1);
  +    m_currentExpressionNodes.quickPop(1);
     }
     
     /**
  @@ -781,9 +775,9 @@
      */
     public final void pushExpressionState(int cn, int en, PrefixResolver nc)
     {
  -    m_currentNodes[m_currentNodesFirstFree++] = cn;
  -    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = cn;
  -    m_prefixResolvers[m_prefixResolversTop++] = nc;
  +    m_currentNodes.push(cn);
  +    m_currentExpressionNodes.push(cn);
  +    m_prefixResolvers.push(nc);
     }
     
     /**
  @@ -791,9 +785,9 @@
      */
     public final void popExpressionState()
     {
  -    m_currentNodesFirstFree--;
  -    m_currentExpressionNodesFirstFree--;
  -    m_prefixResolversTop--;
  +    m_currentNodes.quickPop(1);
  +    m_currentExpressionNodes.quickPop(1);
  +    m_prefixResolvers.pop();
     }
   
   
  @@ -805,20 +799,15 @@
      */
     public final void pushCurrentNode(int n)
     {
  -    m_currentNodes[m_currentNodesFirstFree++] = n;
  +    m_currentNodes.push(n);
     }
     
  -  public int getCurrentNodeFirstFree()
  -  {
  -    return m_currentNodesFirstFree;
  -  }
  -
     /**
      * Pop the current context node.
      */
     public final void popCurrentNode()
     {
  -    m_currentNodesFirstFree--;
  +    m_currentNodes.quickPop(1);
     }
     
     /**
  @@ -876,17 +865,11 @@
     private NodeVector m_predicateRoots = new NodeVector();
   
     /** A stack of the current sub-expression nodes.  */
  -  private int m_currentExpressionNodes[] = new int[RECURSIONLIMIT];
  -  protected int m_currentExpressionNodesFirstFree = 0;
  +  private IntStack m_currentExpressionNodes = new IntStack(RECURSIONLIMIT);
     
        
  -  public int[] getCurrentExpressionNodeStack() { return m_currentExpressionNodes; }
  -  public void setCurrentExpressionNodeStack(int[] nv) { m_currentExpressionNodes = nv; }
  -  public int getCurrentExpressionNodesFirstFree()
  -  {
  -    return m_currentExpressionNodesFirstFree;
  -  }
  -
  +  public IntStack getCurrentExpressionNodeStack() { return m_currentExpressionNodes; }
  +  public void setCurrentExpressionNodeStack(IntStack nv) { m_currentExpressionNodes = nv; }
     
     private IntStack m_predicatePos = new IntStack();
     
  @@ -912,7 +895,7 @@
      */
     public final int getCurrentExpressionNode()
     {
  -    return m_currentExpressionNodes[m_currentExpressionNodesFirstFree-1];
  +    return m_currentExpressionNodes.peek();
     }
   
     /**
  @@ -922,7 +905,7 @@
      */
     public final void pushCurrentExpressionNode(int n)
     {
  -    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = n;
  +    m_currentExpressionNodes.push(n);
     }
   
     /**
  @@ -931,12 +914,11 @@
      */
     public final void popCurrentExpressionNode()
     {
  -    m_currentExpressionNodesFirstFree--;
  +    m_currentExpressionNodes.quickPop(1);
     }
     
  -  private PrefixResolver[] m_prefixResolvers 
  -                                   = new PrefixResolver[RECURSIONLIMIT];
  -  private int m_prefixResolversTop = 0;
  +  private ObjectStack m_prefixResolvers 
  +                                   = new ObjectStack(RECURSIONLIMIT);
   
     /**
      * Get the current namespace context for the xpath.
  @@ -946,7 +928,7 @@
      */
     public final PrefixResolver getNamespaceContext()
     {
  -    return m_prefixResolvers[m_prefixResolversTop-1];
  +    return (PrefixResolver) m_prefixResolvers.peek();
     }
   
     /**
  @@ -957,7 +939,7 @@
      */
     public final void setNamespaceContext(PrefixResolver pr)
     {
  -    m_prefixResolvers[m_prefixResolversTop-1] = pr;
  +    m_prefixResolvers.setTop(pr);
     }
   
     /**
  @@ -968,7 +950,7 @@
      */
     public final void pushNamespaceContext(PrefixResolver pr)
     {
  -    m_prefixResolvers[m_prefixResolversTop++] = pr;
  +    m_prefixResolvers.push(pr);
     }
     
     /**
  @@ -977,7 +959,7 @@
      */
     public final void pushNamespaceContextNull()
     {
  -    m_prefixResolversTop++;
  +    m_prefixResolvers.push(null);
     }
   
     /**
  @@ -985,7 +967,7 @@
      */
     public final void popNamespaceContext()
     {
  -    m_prefixResolversTop--;
  +    m_prefixResolvers.pop();
     }
   
     //==========================================================
  
  
  

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