You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by ro...@locus.apache.org on 2000/01/21 21:47:31 UTC

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

robweir     00/01/21 12:47:31

  Modified:    src/org/apache/xalan/xpath/xml BoolStack.java
                        FormatterToHTML.java
  Log:
  Performance: Here's a smaller/faster BoolStack.  Since this version is
  stricter than the previous one (you can't pop() off an empty stack, for example),
  I also had to fix two places in FormatterToHTML where invalid access was occuring.
  
  Revision  Changes    Path
  1.2       +110 -219  xml-xalan/src/org/apache/xalan/xpath/xml/BoolStack.java
  
  Index: BoolStack.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/BoolStack.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BoolStack.java	1999/12/13 07:40:11	1.1
  +++ BoolStack.java	2000/01/21 20:47:31	1.2
  @@ -59,226 +59,117 @@
   import java.util.EmptyStackException;
   
   /**
  - * Simple vector and stack for boolean values.
  + * Simple stack for boolean values.
    */
  -public class BoolStack
  +public final class BoolStack
   {
  -  
  -  private int m_blocksize;
  -  private boolean m_map[];
  -  private int m_firstFree = 0;
  -  private int m_mapSize;
  -
  -  /**
  -   * Default constructor.  Note that the default 
  -   * block size is very small, for small lists.
  -   */
  -  public BoolStack()
  -  {
  -    m_blocksize = 32;
  -    m_mapSize = m_blocksize;
  -    m_map = new boolean[m_blocksize]; 
  -  }
  -
  -  /**
  -   * Construct a IntVector, using the given block size.
  -   */
  -  public BoolStack(int blocksize)
  -  {
  -    m_blocksize = blocksize;
  -    m_mapSize = blocksize;
  -    m_map = new boolean[blocksize]; 
  -  }
  -  
  -  /**
  -   * Get the length of the list.
  -   */
  -  public final int size()
  -  {
  -    return m_firstFree;
  -  }
  -
  -  /**
  -   * Append a int onto the vector.
  -   */
  -  public final void addElement(boolean value)
  -  {
  -    if((m_firstFree+1) >= m_mapSize)
  -    {
  -      m_mapSize+=m_blocksize;
  -      boolean newMap[] = new boolean[m_mapSize];
  -      System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
  -      m_map = newMap;
  -    }
  -    m_map[m_firstFree] = value;
  -    m_firstFree++;
  -  }
  -
  -  /**
  -   * Inserts the specified node in this vector at the specified index. 
  -   * Each component in this vector with an index greater or equal to 
  -   * the specified index is shifted upward to have an index one greater 
  -   * than the value it had previously. 
  -   */
  -  public final void insertElementAt(boolean value, int at)
  -  {
  -    if((m_firstFree+1) >= m_mapSize)
  -    {
  -      m_mapSize+=m_blocksize;
  -      boolean newMap[] = new boolean[m_mapSize];
  -      System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
  -      m_map = newMap;
  -    }
  -    if(at <= (m_firstFree-1))
  -    {
  -      System.arraycopy(m_map, at, m_map, at+1, m_firstFree-at);
  -    }
  -    m_map[at] = value;
  -    m_firstFree++;
  -  }
  -
  -  /**
  -   * Inserts the specified node in this vector at the specified index. 
  -   * Each component in this vector with an index greater or equal to 
  -   * the specified index is shifted upward to have an index one greater 
  -   * than the value it had previously. 
  -   */
  -  public final void removeAllElements()
  -  {
  -    for(int i = 0; i < m_firstFree; i++)
  -    {
  -      m_map[i] = false;
  -    }
  -    m_firstFree = 0;
  -  }
  -    
  -  /**
  -   * Deletes the component at the specified index. Each component in 
  -   * this vector with an index greater or equal to the specified 
  -   * index is shifted downward to have an index one smaller than 
  -   * the value it had previously. 
  -   */
  -  public final void removeElementAt(int i)
  -  {
  -    if(i > m_firstFree)
  -      System.arraycopy(m_map, i+1, m_map, i, m_firstFree);
  -    else
  -      m_map[i] = false;
  -    m_firstFree--;
  -  }
  -  
  -  /**
  -   * Sets the component at the specified index of this vector to be the 
  -   * specified object. The previous component at that position is discarded. 
  -   * 
  -   * The index must be a value greater than or equal to 0 and less 
  -   * than the current size of the vector. 
  -   */
  -  public final void setElementAt(boolean value, int index)
  -  {
  -    m_map[index] = value;
  -  }
  -
  -  /**
  -   * Get the nth element.
  -   */
  -  public final boolean elementAt(int i)
  -  {
  -    return m_map[i];
  -  }
  -  
  -  /**
  -   * Searches for the first occurence of the given argument, 
  -   * beginning the search at index, and testing for equality 
  -   * using the equals method. 
  -   * @return the index of the first occurrence of the object 
  -   * argument in this vector at position index or later in the 
  -   * vector; returns -1 if the object is not found. 
  -   */
  -  public final int lastIndexOf(boolean elem)
  -  {
  -    for(int i = (m_firstFree - 1); i >= 0; i--)
  -    {
  -      if(m_map[i] == elem)
  -        return i;
  -    }
  -    return java.lang.Integer.MIN_VALUE;
  -  }
  -  
  -  /**
  -   * 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.
  -   * @since   JDK1.0
  -   */
  -  public boolean push(boolean i) 
  -  {
  -    addElement(i);
  -
  -    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.
  -   * @exception  EmptyStackException  if this stack is empty.
  -   * @since      JDK1.0
  -   */
  -  public boolean pop() 
  -  {
  -    boolean	i;
  -    int	len = size();
  -
  -    i = peek();
  -    removeElementAt(len - 1);
  -
  -    return i;
  -  }
  -
  -  /**
  -   * 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. 
  -   * @exception  EmptyStackException  if this stack is empty.
  -   * @since      JDK1.0
  -   */
  -  public boolean peek() 
  -  {
  -    int	len = size();
  -
  -    if (len == 0)
  -      return false;
  -    return elementAt(len - 1);
  -  }
  -
  /**
  -   * 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. 
  -   * @exception  EmptyStackException  if this stack is empty.
  -   * @since      JDK1.0
  -   */
  -  public void setTop(boolean val) 
  -  {
  -    int	len = size();
  -    if (len == 0)
  -      throw new EmptyStackException();
    setElementAt(val, len - 1);
  -  }
  -
  -  /**
  -   * Tests if this stack is empty.
  -   *
  -   * @return  <code>true</code> if this stack is empty;
  -   *          <code>false</code> otherwise.
  -   * @since   JDK1.0
  -   */
  -  public boolean isEmpty() 
  -  {
  -    return size() == 0;
  -  }
  +	private boolean m_values[];
  +	private int m_allocatedSize;
  +	private int m_index;
  +
  +	/**
  +	* Default constructor.  Note that the default 
  +	* block size is very small, for small lists.
  +	*/
  +	public BoolStack()
  +	{
  +		this(32);
  +	}
  +
  +	/**
  +	* Construct a IntVector, using the given block size.
  +	*/
  +	public BoolStack(int size)
  +	{
  +		m_allocatedSize = size;
  +		m_values = new boolean[size];
  +		m_index = -1; 
  +	}
  +
  +	/**
  +	* Get the length of the list.
  +	*/
  +	public int size()
  +	{
  +		return m_index+1;
  +	}
  +
  +	/**
  +	* 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 boolean push(boolean val) 
  +	{
  +		if (m_index == m_allocatedSize-1)
  +			grow();
  +
  +		return (m_values[++m_index] = val);
  +	}
  +
  +	/**
  +	* 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.
  +	* @exception  EmptyStackException  if this stack is empty.
  +	*/
  +	public boolean pop() 
  +	{
  +		try
  +		{
  +			return m_values[m_index--];
  +		}
  +		catch (ArrayIndexOutOfBoundsException  e)
  +		{
  +			throw new EmptyStackException();
  +		}
  +	}
  +
  +	/**
  +	* 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. 
  +	* @exception  EmptyStackException  if this stack is empty.
  +	*/
  +	public boolean peek() 
  +	{
  +		try
  +		{
  +			return m_values[m_index];
  +		}
  +		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.
  +	*/
  +	public boolean isEmpty() 
  +	{
  +		return (m_index == -1);
  +	}
  +
  +	/**
  +	* Grows the size of the stack
  +	*
  +	*/
  +
  +	private void grow()
  +	{
  +		m_allocatedSize*=2;
   
  +		boolean newVector [] = new boolean[m_allocatedSize];
  +		System.arraycopy(m_values, 0 , newVector, 0, m_index+1);
  +
  +		m_values = newVector;
  +	}
   }
  +
  
  
  
  1.20      +3 -2      xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToHTML.java
  
  Index: FormatterToHTML.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToHTML.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- FormatterToHTML.java	2000/01/13 20:19:37	1.19
  +++ FormatterToHTML.java	2000/01/21 20:47:31	1.20
  @@ -569,7 +569,8 @@
   
       if (hasChildNodes) 
       {
  -      m_ispreserve = m_preserves.pop();
  +		if (!m_preserves.isEmpty())
  +			m_preserves.pop();
       }
   
       m_isprevtext = false;
  @@ -779,7 +780,7 @@
         return;
       }
       
  -    if(m_isRawStack.peek())
  +    if(!m_isRawStack.isEmpty() && m_isRawStack.peek())
       {
         try
         {