This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[Patch] Optimizations for java.io.BufferedInputStream...
- From: David Daney <ddaney at avtrex dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Cc: classpath at gnu dot org
- Date: Mon, 14 Mar 2005 15:38:14 -0800
- Subject: [Patch] Optimizations for java.io.BufferedInputStream...
The current skip(int) implementation of BufferedInputStream reads and
ignores data from the underlying stream. We have a program that creates
a BufferedInputStream on an underlying FileInputStream where the file is
on a network mounted file system. Often we skip large portions of the
streams. This causes the entire contents of the files to be transfered
even when we only are interested in a small portion near the end.
This patch does two things:
1) skip now calls skip on the underlying stream when possible (i.e. The
internal buffer is empty and there is no mark).
2) Access the underlying stream directly instead of calling
supper.some_method(). This saves a method call for each operation.
Tested on the HEAD on i686-pc-linux with make check in libjava with no
regresions. No regresions in mauve in the 4.0 branch (HEAD not tested
in mauve due to ICE in mauve)
2005-03-14 David Daney <ddaney@avtrex.com>
* java/io/BufferedInputStream.java (available): Use 'in' instead
of 'super' for underlying stream access.
(close): Ditto.
(read(byte[], int, int)): Ditto.
(refill): Ditto.
(skip): Call skip on underlying stream when possible.
O.K to commit to HEAD?
How about the 4.0 branch for good measure?
David Daney.
Index: java/io/BufferedInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/BufferedInputStream.java,v
retrieving revision 1.12
diff -c -p -r1.12 BufferedInputStream.java
*** java/io/BufferedInputStream.java 9 Mar 2005 22:11:33 -0000 1.12
--- java/io/BufferedInputStream.java 14 Mar 2005 23:10:03 -0000
*************** public class BufferedInputStream extends
*** 158,164 ****
*/
public synchronized int available() throws IOException
{
! return count - pos + super.available();
}
/**
--- 158,164 ----
*/
public synchronized int available() throws IOException
{
! return count - pos + in.available();
}
/**
*************** public class BufferedInputStream extends
*** 173,179 ****
buf = null;
pos = count = 0;
markpos = -1;
! super.close();
}
/**
--- 173,179 ----
buf = null;
pos = count = 0;
markpos = -1;
! in.close();
}
/**
*************** public class BufferedInputStream extends
*** 273,279 ****
off += totalBytesRead;
len -= totalBytesRead;
! while (len > 0 && super.available() > 0 && refill())
{
int remain = Math.min(count - pos, len);
System.arraycopy(buf, pos, b, off, remain);
--- 273,279 ----
off += totalBytesRead;
len -= totalBytesRead;
! while (len > 0 && in.available() > 0 && refill())
{
int remain = Math.min(count - pos, len);
System.arraycopy(buf, pos, b, off, remain);
*************** public class BufferedInputStream extends
*** 327,334 ****
while (n > 0L)
{
! if (pos >= count && !refill())
! break;
int numread = (int) Math.min((long) (count - pos), n);
pos += numread;
--- 327,344 ----
while (n > 0L)
{
! if (pos >= count)
! {
! if (markpos == -1)
! {
! // Buffer is empty and no mark is set, skip on the
! // underlying stream.
! n -= in.skip(n);
! break;
! }
! else if (!refill())
! break;
! }
int numread = (int) Math.min((long) (count - pos), n);
pos += numread;
*************** public class BufferedInputStream extends
*** 369,375 ****
markpos = 0;
}
! int numread = super.read(buf, count, bufferSize);
if (numread <= 0) // EOF
return false;
--- 379,385 ----
markpos = 0;
}
! int numread = in.read(buf, count, bufferSize);
if (numread <= 0) // EOF
return false;