zongaro     2002/11/26 07:02:44

  Modified:    java/src/org/apache/xml/utils Tag: XSLTC_DTM
                        SuballocatedIntVector.java
  Log:
  Added code to addElement to cache most recently added row of the m_map array.
  Elements are almost always added sequentially, so this is of benefit any time
  the m_map array contains more than one row, with very little additional cost
  when it has precisely one row.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.6.10.1  +23 -5     
xml-xalan/java/src/org/apache/xml/utils/SuballocatedIntVector.java
  
  Index: SuballocatedIntVector.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/utils/SuballocatedIntVector.java,v
  retrieving revision 1.6
  retrieving revision 1.6.10.1
  diff -u -r1.6 -r1.6.10.1
  --- SuballocatedIntVector.java        18 Jan 2002 18:54:40 -0000      1.6
  +++ SuballocatedIntVector.java        26 Nov 2002 15:02:44 -0000      1.6.10.1
  @@ -97,6 +97,12 @@
     /** "Shortcut" handle to m_map[0]. Surprisingly helpful for short vectors. 
*/
     protected int m_map0[];
   
  +  /** "Shortcut" handle to most recently added row of m_map.
  +   * Very helpful during construction.
  +   */
  +  protected int m_buildCache[];
  +  protected int m_buildCacheStartIndex;
  +
   
     /**
      * Default constructor.  Note that the default
  @@ -126,6 +132,8 @@
       m_map0=new int[m_blocksize];
       m_map = new int[m_numblocks][];
       m_map[0]=m_map0;
  +    m_buildCache = m_map0;
  +    m_buildCacheStartIndex = 0;
     }
        
     /** We never _did_ use the increasesize parameter, so I'm phasing
  @@ -168,10 +176,13 @@
      */
     public  void addElement(int value)
     {
  -    if(m_firstFree<m_blocksize)
  -      m_map0[m_firstFree++]=value;
  -    else
  -    {
  +    int indexRelativeToCache = m_firstFree - m_buildCacheStartIndex;
  +
  +    // Is the new index an index into the cache row of m_map?
  +    if(indexRelativeToCache >= 0 && indexRelativeToCache < m_blocksize) {
  +      m_buildCache[indexRelativeToCache]=value;
  +      ++m_firstFree;
  +    } else {
         // Growing the outer array should be rare. We initialize to a
         // total of m_blocksize squared elements, which at the default
         // size is 4M integers... and we grow by at least that much each
  @@ -194,10 +205,15 @@
        block=m_map[index]=new int[m_blocksize];
         block[offset]=value;
   
  +      // Cache the current row of m_map.  Next m_blocksize-1
  +      // values added will go to this row.
  +      m_buildCache = block;
  +      m_buildCacheStartIndex = m_firstFree-offset;
  +
         ++m_firstFree;
       }
     }
  -  
  +
     /**
      * Append several int values onto the vector.
      *
  @@ -326,6 +342,8 @@
     public void removeAllElements()
     {
       m_firstFree = 0;
  +    m_buildCache = m_map0;
  +    m_buildCacheStartIndex = 0;
     }
   
     /**
  
  
  

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

Reply via email to