Skip to content

Commit

Permalink
Refactor prefix array & loop logic, use if-s instead (google#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
Degubi authored and inder123 committed Oct 4, 2019
1 parent 236533e commit 9bf25c2
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions gson/src/main/java/com/google/gson/stream/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@
* @since 1.6
*/
public class JsonReader implements Closeable {
/** The only non-execute prefix this parser permits */
private static final char[] NON_EXECUTE_PREFIX = ")]}'\n".toCharArray();
private static final long MIN_INCOMPLETE_INTEGER = Long.MIN_VALUE / 10;

private static final int PEEKED_NONE = 0;
Expand Down Expand Up @@ -1572,18 +1570,18 @@ private void consumeNonExecutePrefix() throws IOException {
nextNonWhitespace(true);
pos--;

if (pos + NON_EXECUTE_PREFIX.length > limit && !fillBuffer(NON_EXECUTE_PREFIX.length)) {
int p = pos;
if (p + 5 > limit && !fillBuffer(5)) {
return;
}

for (int i = 0; i < NON_EXECUTE_PREFIX.length; i++) {
if (buffer[pos + i] != NON_EXECUTE_PREFIX[i]) {
return; // not a security token!
}
char[] buf = buffer;
if(buf[p] != ')' || buf[p + 1] != ']' || buf[p + 2] != '}' || buf[p + 3] != '\'' || buf[p + 4] != '\n') {
return; // not a security token!
}

// we consumed a security token!
pos += NON_EXECUTE_PREFIX.length;
pos += 5;
}

static {
Expand Down

0 comments on commit 9bf25c2

Please sign in to comment.