## src/java.base/share/classes/java/util/regex/Matcher.java

Print this page

*** 176,185 ****
--- 176,193 ----
* so they rely on this field to hold state during a match.
*/
int[] locals;
/**
+ * Storage used by top greedy Loop node to store a specific hash set to
+ * keep the beginning index of the failed repetition match. The nodes
+ * themselves are stateless, so they rely on this field to hold state
+ * during a match.
+ */
+ IntHashSet[] localsPos;
+
+ /**
* Boolean indicating whether or not more input could change
* the results of the last match.
*
* If hitEnd is true, and a match was found, then more input
* might cause a different match to be found.

*** 237,246 ****
--- 245,255 ----
// Allocate state storage
int parentGroupCount = Math.max(parent.capturingGroupCount, 10);
groups = new int[parentGroupCount * 2];
locals = new int[parent.localCount];
+ localsPos = new IntHashSet[parent.localTCNCount];
// Put fields into initial states
reset();
}

*** 373,382 ****
--- 382,392 ----
locals = new int[newPattern.localCount];
for (int i = 0; i < groups.length; i++)
groups[i] = -1;
for (int i = 0; i < locals.length; i++)
locals[i] = -1;
+ localsPos = new IntHashSet[parentPattern.localTCNCount];
modCount++;
return this;
}
/**

*** 395,404 ****
--- 405,418 ----
oldLast = -1;
for(int i=0; i<groups.length; i++)
groups[i] = -1;
for(int i=0; i<locals.length; i++)
locals[i] = -1;
+ for (int i = 0; i < localsPos.length; i++) {
+ if (localsPos[i] != null)
+ localsPos[i].clear();
+ }
lastAppendPosition = 0;
from = 0;
to = getTextLength();
modCount++;
return this;

*** 1704,1713 ****
--- 1718,1731 ----
from = from < 0 ? 0 : from;
this.first = from;
this.oldLast = oldLast < 0 ? from : oldLast;
for (int i = 0; i < groups.length; i++)
groups[i] = -1;
+ for (int i = 0; i < localsPos.length; i++) {
+ if (localsPos[i] != null)
+ localsPos[i].clear();
+ }
acceptMode = NOANCHOR;
boolean result = parentPattern.root.match(this, from, text);
if (!result)
this.first = -1;
this.oldLast = this.last;

*** 1727,1736 ****
--- 1745,1758 ----
from = from < 0 ? 0 : from;
this.first = from;
this.oldLast = oldLast < 0 ? from : oldLast;
for (int i = 0; i < groups.length; i++)
groups[i] = -1;
+ for (int i = 0; i < localsPos.length; i++) {
+ if (localsPos[i] != null)
+ localsPos[i].clear();
+ }
acceptMode = anchor;
boolean result = parentPattern.matchRoot.match(this, from, text);
if (!result)
this.first = -1;
this.oldLast = this.last;