Skip to content

Commit a31506d

Browse files
committed
Use single arraylist instance to track backslashes
1 parent 8513148 commit a31506d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/ESUTF8StreamJsonParser.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class ESUTF8StreamJsonParser extends UTF8StreamJsonParser {
2828
protected int stringEnd = -1;
2929
protected int stringLength;
3030

31+
private final List<Integer> backslashes = new ArrayList<>();
32+
3133
public ESUTF8StreamJsonParser(
3234
IOContext ctxt,
3335
int features,
@@ -70,7 +72,7 @@ protected Text _finishAndReturnText() throws IOException {
7072
final int max = _inputEnd;
7173
final byte[] inputBuffer = _inputBuffer;
7274
stringLength = 0;
73-
List<Integer> backslashes = null;
75+
backslashes.clear();
7476

7577
loop: while (ptr < max) {
7678
int c = inputBuffer[ptr] & 0xFF;
@@ -85,9 +87,6 @@ protected Text _finishAndReturnText() throws IOException {
8587
break loop;
8688
}
8789
assert c == INT_BACKSLASH;
88-
if (backslashes == null) {
89-
backslashes = new ArrayList<>();
90-
}
9190
backslashes.add(ptr);
9291
++ptr;
9392
if (ptr >= max) {
@@ -119,7 +118,7 @@ protected Text _finishAndReturnText() throws IOException {
119118
}
120119

121120
stringEnd = ptr + 1;
122-
if (backslashes == null) {
121+
if (backslashes.isEmpty()) {
123122
return new Text(new XContentString.UTF8Bytes(inputBuffer, startPtr, ptr - startPtr), stringLength);
124123
} else {
125124
byte[] buff = new byte[ptr - startPtr - backslashes.size()];

0 commit comments

Comments
 (0)