Browse Source

Merge pull request #50 from jochenberger/reuse-stringbuilders

reuse StringBuilder instances
pull/54/head
kallestenflo 10 years ago
parent
commit
42f145b67d
  1. 18
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java

18
json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java

@ -308,9 +308,9 @@ public class PathCompiler {
}
criteria.add(createCriteria(pathBuffer, operatorBuffer, valueBuffer));
pathBuffer = new StringBuilder();
operatorBuffer = new StringBuilder();
valueBuffer = new StringBuilder();
pathBuffer.setLength(0);
operatorBuffer.setLength(0);
valueBuffer.setLength(0);
} else if (operatorBuffer.length() > 0) {
valueBuffer.append(current);
@ -369,7 +369,7 @@ public class PathCompiler {
case '\'':
if (propertyIsOpen) {
properties.add(buffer.toString());
buffer = new StringBuilder();
buffer.setLength(0);
propertyIsOpen = false;
} else {
propertyIsOpen = true;
@ -417,7 +417,7 @@ public class PathCompiler {
current = chars[++i];
}
String function = buffer.toString();
buffer = new StringBuilder();
buffer.setLength(0);
if (!function.equals("size") && !function.equals("length")) {
throw new InvalidPathException("Invalid function: @." + function + ". Supported functions are: [(@.length - n)] and [(@.size() - n)]");
}
@ -450,11 +450,11 @@ public class PathCompiler {
current = chars[++i];
}
numbers.add(Integer.parseInt(buffer.toString()));
buffer = new StringBuilder();
buffer.setLength(0);
} else {
//we now this starts with [12:???
numbers.add(Integer.parseInt(buffer.toString()));
buffer = new StringBuilder();
buffer.setLength(0);
current = chars[++i];
//this is a tail slice [:12]
@ -470,13 +470,13 @@ public class PathCompiler {
} else {
sliceBetween = true;
numbers.add(Integer.parseInt(buffer.toString()));
buffer = new StringBuilder();
buffer.setLength(0);
}
}
break;
case ',':
numbers.add(Integer.parseInt(buffer.toString()));
buffer = new StringBuilder();
buffer.setLength(0);
indexSequence = true;
break;
default:

Loading…
Cancel
Save