Changeset 11987


Ignore:
Timestamp:
06/01/09 21:26:37 (12 years ago)
Author:
ehuelsmann
Message:

Don't destroy buffer content when not
necessary: the unread/unwritten part may
be valuable as re-reading may come
at a high cost (that of I/O).

File:
1 edited

Legend:

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

    r11986 r11987  
    384384            encodeAndWrite(cbuf, true, endOfFile);
    385385        } else {
    386             flushBbuf();
     386            flushBbuf(false);
    387387        }
    388388    }
     
    393393            bbufIsDirty = true;
    394394            if (CoderResult.OVERFLOW == r || bbuf.remaining() == 0) {
    395                 flushBbuf();
     395                flushBbuf(false);
    396396                bbuf.clear();
    397397            }
    398398        }
    399399        if (bbuf.position() > 0 && bbufIsDirty && flush) {
    400             flushBbuf();
     400            flushBbuf(false);
    401401        }
    402402    }
    403403
    404404    public final void position(long newPosition) throws IOException {
    405         flushBbuf();
     405        flushBbuf(true);
    406406        long bbufend = bbufpos // in case bbuf is readable, its contents is valid
    407407            + (bbufIsReadable ? bbuf.limit() : bbuf.position()); // beyond position()
     
    423423
    424424    public final long length() throws IOException {
    425         flushBbuf();
     425        flushBbuf(false);
    426426        return fcn.size();
    427427    }
    428428
    429     private final void flushBbuf() throws IOException {
     429    private final void flushBbuf(boolean commitOnly) throws IOException {
    430430        if (! bbufIsDirty)
    431431            return;
     
    436436        // before position(): before re-positioning, this.position()
    437437        // calls this function.
     438        if (commitOnly || bbufIsReadable) {
     439            ByteBuffer dup = bbuf.duplicate();
     440            dup.flip();
     441            fcn.write(dup);
     442            return;
     443        }
    438444        bbuf.flip();
    439445        fcn.write(bbuf);
     
    506512        if (len > bbuf.limit()) {
    507513            if (bbufIsDirty)
    508                 flushBbuf();
     514                flushBbuf(false);
    509515            fcn.write(ByteBuffer.wrap(b, off, len));
    510516        }
     
    518524            bbufIsDirty = true;
    519525            if (bbuf.remaining() == 0) {
    520                 flushBbuf();
     526                flushBbuf(false);
    521527                bbuf.clear();
    522528            }
Note: See TracChangeset for help on using the changeset viewer.