< 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


3956             if (i < matcher.to) {
3957                 return predicate.is(seq.charAt(i)) &&
3958                        next.match(matcher, i + 1, seq);
3959             } else {
3960                 matcher.hitEnd = true;
3961                 return false;
3962             }
3963         }
3964     }
3965 
3966     private static class NFCCharProperty extends Node {
3967         CharPredicate predicate;
3968         NFCCharProperty (CharPredicate predicate) {
3969             this.predicate = predicate;
3970         }
3971 
3972         boolean match(Matcher matcher, int i, CharSequence seq) {
3973             if (i < matcher.to) {
3974                 int ch0 = Character.codePointAt(seq, i);
3975                 int n = Character.charCount(ch0);
3976                 int j = Grapheme.nextBoundary(seq, i, matcher.to);









3977                 if (i + n == j) {    // single, assume nfc cp
3978                     if (predicate.is(ch0))
3979                         return next.match(matcher, j, seq);
3980                 } else {
3981                     while (i + n < j) {
3982                         String nfc = Normalizer.normalize(
3983                             seq.toString().substring(i, j), Normalizer.Form.NFC);
3984                         if (nfc.codePointCount(0, nfc.length()) == 1) {
3985                             if (predicate.is(nfc.codePointAt(0)) &&
3986                                 next.match(matcher, j, seq)) {
3987                                 return true;
3988                             }
3989                         }
3990 
3991                         ch0 = Character.codePointBefore(seq, j);
3992                         j -= Character.charCount(ch0);
3993                     }
3994                 }
3995                 if (j < matcher.to)
3996                     return false;




3956             if (i < matcher.to) {
3957                 return predicate.is(seq.charAt(i)) &&
3958                        next.match(matcher, i + 1, seq);
3959             } else {
3960                 matcher.hitEnd = true;
3961                 return false;
3962             }
3963         }
3964     }
3965 
3966     private static class NFCCharProperty extends Node {
3967         CharPredicate predicate;
3968         NFCCharProperty (CharPredicate predicate) {
3969             this.predicate = predicate;
3970         }
3971 
3972         boolean match(Matcher matcher, int i, CharSequence seq) {
3973             if (i < matcher.to) {
3974                 int ch0 = Character.codePointAt(seq, i);
3975                 int n = Character.charCount(ch0);
3976                 int j = i + n;
3977                 // Fast check if it's necessary to call Normalizer;
3978                 // testing Grapheme.isBoundary is enough for this case
3979                 while (j < matcher.to) {
3980                     int ch1 = Character.codePointAt(seq, j);
3981                     if (Grapheme.isBoundary(ch0, ch1))
3982                         break;
3983                     ch0 = ch1;
3984                     j += Character.charCount(ch1);
3985                 }
3986                 if (i + n == j) {    // single, assume nfc cp
3987                     if (predicate.is(ch0))
3988                         return next.match(matcher, j, seq);
3989                 } else {
3990                     while (i + n < j) {
3991                         String nfc = Normalizer.normalize(
3992                             seq.toString().substring(i, j), Normalizer.Form.NFC);
3993                         if (nfc.codePointCount(0, nfc.length()) == 1) {
3994                             if (predicate.is(nfc.codePointAt(0)) &&
3995                                 next.match(matcher, j, seq)) {
3996                                 return true;
3997                             }
3998                         }
3999 
4000                         ch0 = Character.codePointBefore(seq, j);
4001                         j -= Character.charCount(ch0);
4002                     }
4003                 }
4004                 if (j < matcher.to)
4005                     return false;


< prev index next >