performance hack: better space grow in CharBuffer (speeds up html

parser)
This commit is contained in:
Michael Peter Christen 2012-02-01 23:27:59 +01:00
parent 8b0920b0b5
commit 803963aebd

View File

@ -130,8 +130,7 @@ public final class CharBuffer extends Writer {
}
private void grow(int minSize) {
int newsize = this.buffer.length + 1024;
if (newsize < minSize) newsize = minSize+1;
int newsize = 2 * Math.max(this.buffer.length, minSize);
char[] tmp = new char[newsize];
System.arraycopy(this.buffer, this.offset, tmp, 0, this.length);
this.buffer = tmp;
@ -187,7 +186,7 @@ public final class CharBuffer extends Writer {
}
public CharBuffer append(final char[] bb) {
write(bb);
write(bb, 0, bb.length);
return this;
}
@ -205,14 +204,14 @@ public final class CharBuffer extends Writer {
public CharBuffer append(final String s) {
final char[] temp = new char[s.length()];
s.getChars(0, temp.length, temp, 0);
write(temp);
write(temp, 0, temp.length);
return this;
}
public CharBuffer append(final String s, final int off, final int len) {
final char[] temp = new char[len];
s.getChars(off, (off + len), temp, 0);
write(temp);
write(temp, 0, len);
return this;
}