ClassReader.readClass(InputStream) unnecessary copies read buffer two times
ClassReader.readClass(InputStream) unnecessary copies the read buffer two times
when reading a class. First it creates a buffer using is.available(), then it
increases the buffer size by 1000 bytes and then decreases the buffer size by
1000 bytes. So if a class file is 20000 bytes large, readClass() creates three
buffers of size 20000, 21000 and 20000, which is unnecessary.
This happens always when is.available() returns the complete size of the class
file.
To avoid this, I suggest to try to read one byte if (len == b.length) and
return the initial buffer on EOF.
In ClassReader.java at line 397 change the existing "if" block to:
if (len == b.length) {
int last = is.read();
if( last < 0 )
return b;
byte[] c = new byte[b.length + 1000];
System.arraycopy(b, 0, c, 0, len);
b = c;
b[len++] = (byte) last;
}