Use locals instead of fields when figuring out the buffer's offset line and column. This saves about 2% when parsing twitter data.

This commit is contained in:
Jesse Wilson 2011-12-14 05:49:58 +00:00
parent aa52435951
commit d01d39aa26

View File

@ -796,15 +796,22 @@ public class JsonReader implements Closeable {
* false. * false.
*/ */
private boolean fillBuffer(int minimum) throws IOException { private boolean fillBuffer(int minimum) throws IOException {
char[] buffer = this.buffer;
// Before clobbering the old characters, update where buffer starts // Before clobbering the old characters, update where buffer starts
for (int i = 0; i < pos; i++) { // Using locals here saves ~2%.
int line = bufferStartLine;
int column = bufferStartColumn;
for (int i = 0, p = pos; i < p; i++) {
if (buffer[i] == '\n') { if (buffer[i] == '\n') {
bufferStartLine++; line++;
bufferStartColumn = 1; column = 1;
} else { } else {
bufferStartColumn++; column++;
} }
} }
bufferStartLine = line;
bufferStartColumn = column;
if (limit != pos) { if (limit != pos) {
limit -= pos; limit -= pos;