< prev index next >

src/java.base/share/classes/java/util/regex/Pattern.java

Print this page
rev 57456 : [mq]: 8236034-Use-optimized-Ques-node-for-curly-0-1-quantifier

*** 3241,3265 **** static enum Qtype { GREEDY, LAZY, POSSESSIVE, INDEPENDENT } ! private Node curly(Node prev, int cmin) { int ch = next(); if (ch == '?') { next(); ! return new Curly(prev, cmin, MAX_REPS, Qtype.LAZY); } else if (ch == '+') { next(); ! return new Curly(prev, cmin, MAX_REPS, Qtype.POSSESSIVE); } if (prev instanceof BmpCharProperty) { return new BmpCharPropertyGreedy((BmpCharProperty)prev, cmin); } else if (prev instanceof CharProperty) { return new CharPropertyGreedy((CharProperty)prev, cmin); } ! return new Curly(prev, cmin, MAX_REPS, Qtype.GREEDY); } /** * Processes repetition. If the next character peeked is a quantifier * then new nodes must be appended to handle the repetition. --- 3241,3272 ---- static enum Qtype { GREEDY, LAZY, POSSESSIVE, INDEPENDENT } ! private Qtype qtype() { int ch = next(); if (ch == '?') { next(); ! return Qtype.LAZY; } else if (ch == '+') { next(); ! return Qtype.POSSESSIVE; ! } ! return Qtype.GREEDY; } + + private Node curly(Node prev, int cmin) { + Qtype qtype = qtype(); + if (qtype == Qtype.GREEDY) { if (prev instanceof BmpCharProperty) { return new BmpCharPropertyGreedy((BmpCharProperty)prev, cmin); } else if (prev instanceof CharProperty) { return new CharPropertyGreedy((CharProperty)prev, cmin); } ! } ! return new Curly(prev, cmin, MAX_REPS, qtype); } /** * Processes repetition. If the next character peeked is a quantifier * then new nodes must be appended to handle the repetition.
*** 3267,3285 **** */ private Node closure(Node prev) { int ch = peek(); switch (ch) { case '?': ! ch = next(); ! if (ch == '?') { ! next(); ! return new Ques(prev, Qtype.LAZY); ! } else if (ch == '+') { ! next(); ! return new Ques(prev, Qtype.POSSESSIVE); ! } ! return new Ques(prev, Qtype.GREEDY); case '*': return curly(prev, 0); case '+': return curly(prev, 1); case '{': --- 3274,3284 ---- */ private Node closure(Node prev) { int ch = peek(); switch (ch) { case '?': ! return new Ques(prev, qtype()); case '*': return curly(prev, 0); case '+': return curly(prev, 1); case '{':
*** 3312,3331 **** } if (ch != '}') throw error("Unclosed counted closure"); if (cmax < cmin) throw error("Illegal repetition range"); ! ch = peek(); ! if (ch == '?') { ! next(); ! return new Curly(prev, cmin, cmax, Qtype.LAZY); ! } else if (ch == '+') { ! next(); ! return new Curly(prev, cmin, cmax, Qtype.POSSESSIVE); ! } else { ! return new Curly(prev, cmin, cmax, Qtype.GREEDY); ! } } else { throw error("Illegal repetition"); } default: return prev; --- 3311,3324 ---- } if (ch != '}') throw error("Unclosed counted closure"); if (cmax < cmin) throw error("Illegal repetition range"); ! unread(); ! return (cmin == 0 && cmax == 1) ! ? new Ques(prev, qtype()) ! : new Curly(prev, cmin, cmax, qtype()); } else { throw error("Illegal repetition"); } default: return prev;
< prev index next >