From 207f3c6ffb4f1ce5ee9d85af4c4111571edbd088 Mon Sep 17 00:00:00 2001 From: Jochen Berger Date: Mon, 15 Sep 2014 16:06:25 +0200 Subject: [PATCH] reuse StringBuilder instances --- .../jayway/jsonpath/internal/PathCompiler.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java b/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java index 8f35a65c..a6e20944 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java +++ b/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: