From d01d39aa26f71fc0e40fecb3ce4b7388cc1f985b Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Wed, 14 Dec 2011 05:49:58 +0000 Subject: [PATCH] Use locals instead of fields when figuring out the buffer's offset line and column. This saves about 2% when parsing twitter data. --- .../java/com/google/gson/stream/JsonReader.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index 88876833..f273876e 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -796,15 +796,22 @@ public class JsonReader implements Closeable { * false. */ private boolean fillBuffer(int minimum) throws IOException { + char[] buffer = this.buffer; + // 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') { - bufferStartLine++; - bufferStartColumn = 1; + line++; + column = 1; } else { - bufferStartColumn++; + column++; } } + bufferStartLine = line; + bufferStartColumn = column; if (limit != pos) { limit -= pos;