Changeset 11971


Ignore:
Timestamp:
05/31/09 19:46:23 (13 years ago)
Author:
ehuelsmann
Message:

Disentangle flushBbuf() and read(char[]) in
RandomAccessCharacterFile?; a step toward simplification.

Note: It looks like calling fcn.size() is a

performance killer on Windows. Working toward removal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java

    r11970 r11971  
    325325        boolean decodeWasUnderflow = false;
    326326        boolean atEof = false;
    327         while ((cbuf.remaining() > 0) && dataIsAvailableForRead()
    328                && ! atEof) {
     327        while ((cbuf.remaining() > 0) && dataIsAvailableForRead() && ! atEof) {
    329328            if ((bbuf.remaining() == 0) || decodeWasUnderflow) {
    330             // need to read from the file.
    331             flushBbuf(); // in case bbuf is dirty.
    332             // update bbufpos.
    333             bbufpos += bbuf.position();
    334             int partialBytes = bbuf.remaining(); // partialBytes > 0 happens when decodeWasUnderflow
    335             // if reads and writes are mixed, we may need to seek first.
    336             if (bbufpos + partialBytes != fcnpos) {
    337                 fcn.position(bbufpos + partialBytes);
    338             }
    339             // need to read data from file.
    340             bbuf.compact();
    341             //###FIXME: we're ignoring end-of-stream here!!!
    342             atEof = (fcn.read(bbuf) == -1);
    343             bbuf.flip();
    344             fcnpos = bbufpos + bbuf.remaining();
     329                // need to read from the file.
     330
     331                if (bbufIsDirty) {
     332                    bbuf.flip();
     333                    fcn.position(bbufpos);
     334                    fcn.write(bbuf);
     335                    bbufpos = bbufpos+bbuf.position();
     336                    bbuf.clear();
     337                } else {
     338                    fcn.position(bbufpos + bbuf.limit());
     339                    bbufpos += bbuf.position();
     340                    bbuf.compact();
     341                }
     342
     343                atEof = (fcn.read(bbuf) == -1);
     344                fcnpos = fcn.position();
     345                // update bbufpos.
     346                bbuf.flip();
    345347            }
    346348            CoderResult r = cdec.decode(bbuf, cbuf, pointingAtEOF() );
Note: See TracChangeset for help on using the changeset viewer.