[kaffe] CVS kaffe (guilhem): libraries/javalib/java/io/BufferedInputStream.java

Kaffe CVS cvs-commits at kaffe.org
Sat Mar 6 13:54:03 PST 2004


PatchSet 4481 
Date: 2004/03/06 21:36:35
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
        * libraries/javalib/java/io/BufferedInputStream.java
        (mark, refill) Make an incremental mark buffer allocation.
        New field marktarget, CHUNKSIZE.

Members: 
	ChangeLog:1.2061->1.2062 
	libraries/javalib/java/io/BufferedInputStream.java:1.12->1.13 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2061 kaffe/ChangeLog:1.2062
--- kaffe/ChangeLog:1.2061	Fri Mar  5 20:01:11 2004
+++ kaffe/ChangeLog	Sat Mar  6 21:36:35 2004
@@ -1,3 +1,9 @@
+2004-03-06  Guilhem Lavaux <guilhem at kaffe.org>
+
+	* libraries/javalib/java/io/BufferedInputStream.java
+	(mark, refill) Make an incremental mark buffer allocation.
+	New field marktarget, CHUNKSIZE.
+
 2004-03-05  Cliff Wright <cliffw at messagegate.com>
 
 	* libraries/clib/io/FileDescriptor.c:
Index: kaffe/libraries/javalib/java/io/BufferedInputStream.java
diff -u kaffe/libraries/javalib/java/io/BufferedInputStream.java:1.12 kaffe/libraries/javalib/java/io/BufferedInputStream.java:1.13
--- kaffe/libraries/javalib/java/io/BufferedInputStream.java:1.12	Sun Nov  2 13:29:36 2003
+++ kaffe/libraries/javalib/java/io/BufferedInputStream.java	Sat Mar  6 21:36:37 2004
@@ -103,6 +103,19 @@
   protected int marklimit = 0;
 
   /**
+   * This is the maximum size we have to allocate for the mark buffer.
+   * This number may be huge (Integer.MAX_VALUE). The class will continue
+   * to allocate new chunks (specified by <code>CHUNKSIZE</code>) until the
+   * the size specified by this field is achieved.
+   */
+  protected int marktarget = 0;
+
+  /**
+   * This is the number of bytes to allocate to reach marktarget.
+   */
+  static final protected int CHUNKSIZE = 1024;
+
+  /**
    * This method initializes a new <code>BufferedInputStream</code> that will
    * read from the specified subordinate stream with a default buffer size
    * of 2048 bytes
@@ -183,7 +196,9 @@
    */
   public synchronized void mark(int readlimit)
   {
-    marklimit = readlimit;
+    marktarget = marklimit = readlimit;
+    if (marklimit > CHUNKSIZE)
+	marklimit = CHUNKSIZE;
     markpos = pos;
   }
 
@@ -337,13 +352,16 @@
 	pos -= markpos;
 	markpos = 0;
       }
-    else if (marklimit >= buf.length)	// BTW, markpos == 0
+    else if (marktarget >= buf.length && marklimit < marktarget)	// BTW, markpos == 0
       {
 	// Need to grow the buffer now to have room for marklimit bytes.
 	// Note that the new buffer is one greater than marklimit.
 	// This is so that there will be one byte past marklimit to be read
 	// before having to call refill again, thus allowing marklimit to be
 	// invalidated.  That way refill doesn't have to check marklimit.
+	marklimit += CHUNKSIZE;
+	if (marklimit >= marktarget)
+	  marklimit = marktarget;
 	byte[] newbuf = new byte[marklimit + 1];
 	System.arraycopy(buf, 0, newbuf, 0, count);
 	buf = newbuf;




More information about the kaffe mailing list