Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 11

- name: Checkout ion-java from the new commit.
Expand Down
26 changes: 22 additions & 4 deletions src/com/amazon/ion/impl/IonReaderTextRawTokensX.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint;
import com.amazon.ion.util.IonTextUtils;
import java.io.IOException;
import java.util.ArrayList;

/**
* Tokenizer for the Ion text parser in IonTextIterator. This
Expand Down Expand Up @@ -107,6 +108,10 @@ public Appendable append(char c) throws IOException
*/
private int _base64_prefetch_stack;

// This value was chosen somewhat arbitrarily; it can/should be changed if it is found to be insufficient.
private static final int CONTAINER_STACK_INITIAL_CAPACITY = 16;
// Used for tracking terminator characters when skipping a container
private final ArrayList<Integer> containerSkipTerminatorStack = new ArrayList<>(CONTAINER_STACK_INITIAL_CAPACITY);

/**
* IonTokenReader constructor requires a UnifiedInputStream
Expand Down Expand Up @@ -1206,6 +1211,11 @@ protected void skip_over_sexp() throws IOException
private void skip_over_container(int terminator) throws IOException
{
assert( terminator == '}' || terminator == ']' || terminator == ')' );

// In theory, this should be empty at the start and end of every call to this
// method, but we'll clear it here anyway just in case.
containerSkipTerminatorStack.clear();

int c;

for (;;) {
Expand All @@ -1217,7 +1227,12 @@ private void skip_over_container(int terminator) throws IOException
case ']':
case ')':
if (c == terminator) { // no point is checking this on every char
return;
if (containerSkipTerminatorStack.isEmpty()) {
return;
} else {
// Pop one off the stack to continue
terminator = containerSkipTerminatorStack.remove(containerSkipTerminatorStack.size() - 1);
}
}
break;
case '"':
Expand All @@ -1233,10 +1248,12 @@ private void skip_over_container(int terminator) throws IOException
}
break;
case '(':
skip_over_container(')');
containerSkipTerminatorStack.add(terminator);
terminator = ')';
break;
case '[':
skip_over_container(']');
containerSkipTerminatorStack.add(terminator);
terminator = ']';
break;
case '{':
// this consumes lobs as well since the double
Expand Down Expand Up @@ -1273,7 +1290,8 @@ else if (c == '}') {
}
else {
unread_char(c);
skip_over_container('}');
containerSkipTerminatorStack.add(terminator);
terminator = '}';
}
break;
default:
Expand Down