diff --git a/src/main/java/io/usethesource/vallang/impl/primitive/StringValue.java b/src/main/java/io/usethesource/vallang/impl/primitive/StringValue.java index 5dce7d71..e52c85a8 100644 --- a/src/main/java/io/usethesource/vallang/impl/primitive/StringValue.java +++ b/src/main/java/io/usethesource/vallang/impl/primitive/StringValue.java @@ -1257,7 +1257,7 @@ public AbstractString rotateLeftRight() { public OfInt iterator() { return new OfInt() { final Deque todo = new ArrayDeque<>(depth); - OfInt currentLeaf = leftmostLeafIterator(todo, LazyConcatString.this); + OfInt currentLeaf = leftmostLeaf(todo, LazyConcatString.this).iterator(); @Override public boolean hasNext() { @@ -1271,7 +1271,7 @@ public int nextInt() { if (!currentLeaf.hasNext() && !todo.isEmpty()) { // now we back track to the previous node we went left from, // take the right branch and continue with its first leaf: - currentLeaf = leftmostLeafIterator(todo, todo.pop()); + currentLeaf = leftmostLeaf(todo, todo.pop()).iterator(); } assert currentLeaf.hasNext() || todo.isEmpty(); @@ -1284,7 +1284,7 @@ public int nextInt() { public Iterator iterateParts() { return new Iterator<> () { final Deque todo = new ArrayDeque<>(depth); - Iterator currentLeaf = leftmostLeafIteratorParts(todo, LazyConcatString.this); + Iterator currentLeaf = leftmostLeaf(todo, LazyConcatString.this).iterateParts(); @Override public boolean hasNext() { return currentLeaf.hasNext(); /* || !todo.isEmpty() is unnecessary due to post-condition of nextInt() */ @@ -1296,7 +1296,7 @@ public CharBuffer next() { if (!currentLeaf.hasNext() && !todo.isEmpty()) { // now we back track to the previous node we went left from, // take the right branch and continue with its first leaf: - currentLeaf = leftmostLeafIteratorParts(todo, todo.pop()); + currentLeaf = leftmostLeaf(todo, todo.pop()).iterateParts(); } assert currentLeaf.hasNext() || todo.isEmpty(); @@ -1312,7 +1312,7 @@ public CharBuffer next() { * the path of nodes to this leaf as a side-effect in the todo * stack. */ - private static Iterator leftmostLeafIteratorParts(Deque todo, IStringTreeNode start) { + private static IStringTreeNode leftmostLeaf(Deque todo, IStringTreeNode start) { IStringTreeNode cur = start; while (cur.depth() > 1) { @@ -1320,26 +1320,9 @@ private static Iterator leftmostLeafIteratorParts(Deque todo, IStringTreeNode start) { - IStringTreeNode cur = start; - - while (cur.depth() > 1) { - todo.push(cur.right()); - cur = cur.left(); - } - - return cur.iterator(); - } } private static class IndentedString extends AbstractString {