Skip to content

Commit 1e682d1

Browse files
authored
perf: reuse one end-of-input IOException per SimpleCharStream (#2962)
1 parent 8976e8e commit 1e682d1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class SimpleCharStream {
5151
// line, column and absolute position of each match begun since the last positionSpecialTokens()
5252
private int[] matchBegins = new int[24];
5353
private int matchBeginCount = 0;
54+
// signals the end of input to the token manager, which discards it; created once per stream
55+
// because filling in the stack trace of the deep lookahead recursion dominates short inputs
56+
private java.io.IOException endOfInput;
5457
int bufsize;
5558
int available;
5659
int tokenBegin;
@@ -200,7 +203,10 @@ protected void FillBuff() throws java.io.IOException {
200203
try {
201204
if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) {
202205
inputStream.close();
203-
throw new java.io.IOException();
206+
if (endOfInput == null) {
207+
endOfInput = new java.io.IOException();
208+
}
209+
throw endOfInput;
204210
} else {
205211
maxNextCharInd += i;
206212
}

0 commit comments

Comments
 (0)