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

Loading…
Cancel
Save