lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 36623] - RAMInputStream without further buffering
Date Mon, 12 Sep 2005 20:11:50 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=36623>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=36623





------- Additional Comments From cutting@apache.org  2005-09-12 22:11 -------
This readByte() implementation will probably be slower than
BufferedIndexInput's.  In particular, the call to buffers.elementAt() is not
cheap.  It would be faster to cache the current buffer in a field.  Fastest
would be to also cache the position in the buffer, something like the following
(untested):

private static final EMPTY_BUFFER = new byte[0];
private byte[] buffer = EMPTY_BUFFER;
private int bufferPosition;

public byte readByte() {
  if (bufferPosition == buffer.length) {
    pointer += buffer.length;
    updateBuffer();
  }
  return buffer[bufferPosition++];
}

public byte readBytes(byte[] dest, int destOffset, int len) {
  int start = pointer + bufferPosition;
  ... your code ...
  updateBuffer();
}

public void seek(long pos) {
  pointer = (int)pos;
  updateBuffer();
}

public long getFilePointer() {
  return pointer + bufferPosition;
}

private void updateBuffer() {
  if (pointer < length) {
    buffer = file.buffers.elementAt(pointer/BUFFER_SIZE));
    bufferPosition = pointer%BUFFER_SIZE;
  } else {
    buffer = EMPTY_BUFFER;
    bufferPosition = 0;
  }
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message