< prev index next >
src/java.base/share/classes/java/util/regex/Pattern.java
Print this page
rev 16589 : 8160302: Reduce number of lambdas created when loading java.util.regex.Pattern
Reviewed-by: sherman
*** 1493,1503 ****
if (Character.getType(ch1) == Character.NON_SPACING_MARK) {
Set<String> altns = new LinkedHashSet<>();
altns.add(seq);
produceEquivalentAlternation(nfd, altns);
dst.append("(?:");
! altns.forEach( s -> dst.append(s + "|"));
dst.delete(dst.length() - 1, dst.length());
dst.append(")");
continue;
}
}
--- 1493,1503 ----
if (Character.getType(ch1) == Character.NON_SPACING_MARK) {
Set<String> altns = new LinkedHashSet<>();
altns.add(seq);
produceEquivalentAlternation(nfd, altns);
dst.append("(?:");
! altns.forEach( s -> dst.append(s).append('|'));
dst.delete(dst.length() - 1, dst.length());
dst.append(")");
continue;
}
}
*** 2140,2155 ****
node = new Dollar(has(MULTILINE));
break;
case '.':
next();
if (has(DOTALL)) {
! node = new CharProperty(ALL);
} else {
if (has(UNIX_LINES)) {
! node = new CharProperty(UNIXDOT);
} else {
! node = new CharProperty(DOT);
}
}
break;
case '|':
case ')':
--- 2140,2155 ----
node = new Dollar(has(MULTILINE));
break;
case '.':
next();
if (has(DOTALL)) {
! node = new CharProperty(ALL());
} else {
if (has(UNIX_LINES)) {
! node = new CharProperty(UNIXDOT());
} else {
! node = new CharProperty(DOT());
}
}
break;
case '|':
case ')':
*** 2374,2384 ****
case 'C':
break;
case 'D':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.DIGIT : CharPredicates.ASCII_DIGIT;
predicate = predicate.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
--- 2374,2384 ----
case 'C':
break;
case 'D':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.DIGIT() : CharPredicates.ASCII_DIGIT();
predicate = predicate.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
*** 2389,2399 ****
if (inclass) break;
if (create) root = new LastMatch();
return -1;
case 'H':
if (create) {
! predicate = HorizWS.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'I':
--- 2389,2399 ----
if (inclass) break;
if (create) root = new LastMatch();
return -1;
case 'H':
if (create) {
! predicate = HorizWS().negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'I':
*** 2413,2442 ****
if (create) root = new LineEnding();
return -1;
case 'S':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WHITE_SPACE : CharPredicates.ASCII_SPACE;
predicate = predicate.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'T':
case 'U':
break;
case 'V':
if (create) {
! predicate = VertWS.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'W':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WORD : CharPredicates.ASCII_WORD;
predicate = predicate.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
--- 2413,2442 ----
if (create) root = new LineEnding();
return -1;
case 'S':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WHITE_SPACE() : CharPredicates.ASCII_SPACE();
predicate = predicate.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'T':
case 'U':
break;
case 'V':
if (create) {
! predicate = VertWS().negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'W':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WORD() : CharPredicates.ASCII_WORD();
predicate = predicate.negate();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
*** 2478,2488 ****
case 'c':
return c();
case 'd':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.DIGIT : CharPredicates.ASCII_DIGIT;
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'e':
--- 2478,2488 ----
case 'c':
return c();
case 'd':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.DIGIT() : CharPredicates.ASCII_DIGIT();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'e':
*** 2491,2501 ****
return '\f';
case 'g':
break;
case 'h':
if (create) {
! predicate = HorizWS;
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'i':
--- 2491,2501 ----
return '\f';
case 'g':
break;
case 'h':
if (create) {
! predicate = HorizWS();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'i':
*** 2529,2539 ****
case 'r':
return '\r';
case 's':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WHITE_SPACE : CharPredicates.ASCII_SPACE;
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 't':
--- 2529,2539 ----
case 'r':
return '\r';
case 's':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WHITE_SPACE() : CharPredicates.ASCII_SPACE();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 't':
*** 2550,2568 ****
// which a single definite value (0x0B) is expected. For
// compatibility concern '\013'/0x0B is returned if isrange.
if (isrange)
return '\013';
if (create) {
! predicate = VertWS;
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'w':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WORD : CharPredicates.ASCII_WORD;
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'x':
--- 2550,2568 ----
// which a single definite value (0x0B) is expected. For
// compatibility concern '\013'/0x0B is returned if isrange.
if (isrange)
return '\013';
if (create) {
! predicate = VertWS();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'w':
if (create) {
predicate = has(UNICODE_CHARACTER_CLASS) ?
! CharPredicates.WORD() : CharPredicates.ASCII_WORD();
if (!inclass)
root = newCharProperty(predicate);
}
return -1;
case 'x':
*** 2702,2712 ****
(5)KelvinSign u+212a
toLowerCase(u+212a) ==> u+006B
(6)AngstromSign u+212b
toLowerCase(u+212b) ==> u+00e5
*/
- int d;
if (ch < 256 &&
!(has(CASE_INSENSITIVE) && has(UNICODE_CASE) &&
(ch == 0xff || ch == 0xb5 ||
ch == 0x49 || ch == 0x69 || //I and i
ch == 0x53 || ch == 0x73 || //S and s
--- 2702,2711 ----
*** 5382,5392 ****
type = n;
this.useUWORD = useUWORD;
}
boolean isWord(int ch) {
! return useUWORD ? CharPredicates.WORD.is(ch)
: (ch == '_' || Character.isLetterOrDigit(ch));
}
int check(Matcher matcher, int i, CharSequence seq) {
int ch;
--- 5381,5391 ----
type = n;
this.useUWORD = useUWORD;
}
boolean isWord(int ch) {
! return useUWORD ? CharPredicates.WORD().is(ch)
: (ch == '_' || Character.isLetterOrDigit(ch));
}
int check(Matcher matcher, int i, CharSequence seq) {
int ch;
*** 5678,5714 ****
}
/**
* matches a Perl vertical whitespace
*/
! static BmpCharPredicate VertWS = cp ->
! (cp >= 0x0A && cp <= 0x0D) || cp == 0x85 || cp == 0x2028 || cp == 0x2029;
/**
* matches a Perl horizontal whitespace
*/
! static BmpCharPredicate HorizWS = cp ->
cp == 0x09 || cp == 0x20 || cp == 0xa0 || cp == 0x1680 ||
cp == 0x180e || cp >= 0x2000 && cp <= 0x200a || cp == 0x202f ||
cp == 0x205f || cp == 0x3000;
/**
* for the Unicode category ALL and the dot metacharacter when
* in dotall mode.
*/
! static CharPredicate ALL = ch -> true;
/**
* for the dot metacharacter when dotall is not enabled.
*/
! static CharPredicate DOT = ch -> (ch != '\n' && ch != '\r'
&& (ch|1) != '\u2029'
&& ch != '\u0085');
/**
* the dot metacharacter when dotall is not enabled but UNIX_LINES is enabled.
*/
! static CharPredicate UNIXDOT = ch -> ch != '\n';
/**
* Indicate that matches a Supplementary Unicode character
*/
static CharPredicate SingleS(int c) {
--- 5677,5725 ----
}
/**
* matches a Perl vertical whitespace
*/
! static BmpCharPredicate VertWS() {
! return cp -> (cp >= 0x0A && cp <= 0x0D) ||
! cp == 0x85 || cp == 0x2028 || cp == 0x2029;
! }
/**
* matches a Perl horizontal whitespace
*/
! static BmpCharPredicate HorizWS() {
! return cp ->
cp == 0x09 || cp == 0x20 || cp == 0xa0 || cp == 0x1680 ||
cp == 0x180e || cp >= 0x2000 && cp <= 0x200a || cp == 0x202f ||
cp == 0x205f || cp == 0x3000;
+ }
/**
* for the Unicode category ALL and the dot metacharacter when
* in dotall mode.
*/
! static CharPredicate ALL() {
! return ch -> true;
! }
/**
* for the dot metacharacter when dotall is not enabled.
*/
! static CharPredicate DOT() {
! return ch ->
! (ch != '\n' && ch != '\r'
&& (ch|1) != '\u2029'
&& ch != '\u0085');
+ }
+
/**
* the dot metacharacter when dotall is not enabled but UNIX_LINES is enabled.
*/
! static CharPredicate UNIXDOT() {
! return ch -> ch != '\n';
! }
/**
* Indicate that matches a Supplementary Unicode character
*/
static CharPredicate SingleS(int c) {
< prev index next >