< prev index next >
src/java.base/share/classes/java/util/regex/Pattern.java
Print this page
rev 55125 : 8225061: Performance regression in Regex
Reviewed-by: TBD
*** 3971,3981 ****
boolean match(Matcher matcher, int i, CharSequence seq) {
if (i < matcher.to) {
int ch0 = Character.codePointAt(seq, i);
int n = Character.charCount(ch0);
! int j = Grapheme.nextBoundary(seq, i, matcher.to);
if (i + n == j) { // single, assume nfc cp
if (predicate.is(ch0))
return next.match(matcher, j, seq);
} else {
while (i + n < j) {
--- 3971,3990 ----
boolean match(Matcher matcher, int i, CharSequence seq) {
if (i < matcher.to) {
int ch0 = Character.codePointAt(seq, i);
int n = Character.charCount(ch0);
! int j = i + n;
! // Fast check if it's necessary to call Normalizer;
! // testing Grapheme.isBoundary is enough for this case
! while (j < matcher.to) {
! int ch1 = Character.codePointAt(seq, j);
! if (Grapheme.isBoundary(ch0, ch1))
! break;
! ch0 = ch1;
! j += Character.charCount(ch1);
! }
if (i + n == j) { // single, assume nfc cp
if (predicate.is(ch0))
return next.match(matcher, j, seq);
} else {
while (i + n < j) {
< prev index next >