Changeset 2527


Ignore:
Timestamp:
04/02/07 11:01:52 (13 years ago)
Author:
melissa
Message:

Use a static int array to keep track of previous buffer sizes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/RandomAccessStream.java

    r2455 r2527  
    6262  private static int openFiles = 0; 
    6363 
     64  /** Recent buffer sizes. */ 
     65  private static int[] bufferSizes = new int[MAX_HISTORY]; 
     66 
    6467  // -- Fields -- 
    6568 
     
    8588  protected byte[] buf; 
    8689 
    87   /** Recent buffer sizes. */ 
    88   protected Vector recent; 
    89  
    9090  /** Endianness of the stream. */ 
    9191  protected boolean littleEndian = false; 
     
    9393  /** Number of bytes by which to extend the stream. */ 
    9494  protected int ext = 0; 
     95 
     96  /** Number of valid entries in the buffer size array. */ 
     97  protected int lastValid = 0; 
    9598 
    9699  // -- Constructors -- 
     
    111114      raf.readFully(buf); 
    112115      raf.seek(0); 
    113       recent = new Vector(); 
    114       recent.add(new Integer(MAX_OVERHEAD / 2)); 
     116      bufferSizes[0] = MAX_OVERHEAD / 2;  
     117      lastValid = 1;  
    115118      nextMark = MAX_OVERHEAD; 
    116119    } 
     
    408411    int ndx = 0; 
    409412 
    410     while ((ndx < recent.size()) && (ndx < MAX_HISTORY)) { 
    411       int size = ((Integer) recent.get(ndx)).intValue(); 
     413    while ((ndx < lastValid) && (ndx < MAX_HISTORY)) { 
     414      int size = bufferSizes[ndx];  
    412415      sum += (size * ((ndx / (MAX_HISTORY / 5)) + 1)); 
    413416      div += (ndx / (MAX_HISTORY / 5)) + 1; 
     
    417420    int newSize = sum / div; 
    418421    if (newSize > MAX_OVERHEAD) newSize = MAX_OVERHEAD; 
    419     if (recent.size() < MAX_HISTORY) recent.add(new Integer(newSize)); 
    420     else { 
    421       recent.remove(0); 
    422       recent.add(new Integer(newSize)); 
     422    if (lastValid < MAX_HISTORY) {/*recent.add(new Integer(newSize)); */ 
     423      bufferSizes[lastValid] = newSize; 
     424      lastValid++; 
     425    } 
     426    else { 
     427      bufferSizes[0] = newSize;  
    423428    } 
    424429 
     
    434439  protected int checkEfficiency(int toRead) throws IOException { 
    435440    if (fileCache.get(this) == Boolean.FALSE) reopen(); 
    436     int oldBufferSize = 0; 
    437     if (recent != null) { 
    438       oldBufferSize = ((Integer) recent.get(recent.size() - 1)).intValue(); 
    439     } 
     441    int oldBufferSize = bufferSizes[bufferSizes.length - 1]; 
    440442 
    441443    if (dis != null) { 
     
    460462      } 
    461463 
    462       if (recent.size() < MAX_HISTORY) recent.add(new Integer(MAX_OVERHEAD)); 
     464      if (lastValid < MAX_HISTORY) { 
     465        bufferSizes[lastValid] = MAX_OVERHEAD; 
     466        lastValid++; 
     467      } 
    463468      else { 
    464         recent.remove(0); 
    465         recent.add(new Integer(MAX_OVERHEAD)); 
     469        bufferSizes[0] = MAX_OVERHEAD;  
    466470      } 
    467471 
Note: See TracChangeset for help on using the changeset viewer.