Fri, 12 Apr 2013 16:31:16 +0200
8011884: Regexp literals are compiled twice
Reviewed-by: lagergren, sundar
1.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java Thu Apr 11 12:16:39 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java Fri Apr 12 16:31:16 2013 +0200 1.3 @@ -156,9 +156,6 @@ 1.4 1.5 env.memNodes = null; 1.6 1.7 - new ArrayCompiler(this).compile(); 1.8 - //new AsmCompiler(this).compile(); 1.9 - 1.10 if (regex.numRepeat != 0 || regex.btMemEnd != 0) { 1.11 regex.stackPopLevel = StackPopLevel.ALL; 1.12 } else {
2.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java Thu Apr 11 12:16:39 2013 +0200 2.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java Fri Apr 12 16:31:16 2013 +0200 2.3 @@ -55,8 +55,9 @@ 2.4 int[]repeatRangeLo; 2.5 int[]repeatRangeHi; 2.6 2.7 - public WarnCallback warnings; 2.8 - public MatcherFactory factory; 2.9 + WarnCallback warnings; 2.10 + MatcherFactory factory; 2.11 + private Analyser analyser; 2.12 2.13 int options; 2.14 int userOptions; 2.15 @@ -140,19 +141,33 @@ 2.16 this.caseFoldFlag = caseFoldFlag; 2.17 this.warnings = warnings; 2.18 2.19 - new Analyser(new ScanEnvironment(this, syntax), chars, p, end).compile(); 2.20 + this.analyser = new Analyser(new ScanEnvironment(this, syntax), chars, p, end); 2.21 + this.analyser.compile(); 2.22 2.23 this.warnings = null; 2.24 } 2.25 2.26 + public void compile() { 2.27 + if (factory == null && analyser != null) { 2.28 + Compiler compiler = new ArrayCompiler(analyser); 2.29 + analyser = null; // only do this once 2.30 + compiler.compile(); 2.31 + } 2.32 + } 2.33 + 2.34 public Matcher matcher(char[] chars) { 2.35 return matcher(chars, 0, chars.length); 2.36 } 2.37 2.38 public Matcher matcher(char[] chars, int p, int end) { 2.39 + compile(); 2.40 return factory.create(this, chars, p, end); 2.41 } 2.42 2.43 + public WarnCallback getWarnings() { 2.44 + return warnings; 2.45 + } 2.46 + 2.47 public int numberOfCaptures() { 2.48 return numMem; 2.49 }
3.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java Thu Apr 11 12:16:39 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java Fri Apr 12 16:31:16 2013 +0200 3.3 @@ -231,12 +231,12 @@ 3.4 break; 3.5 3.6 case DEL: 3.7 - env.reg.warnings.warn(new String(chars, p, end) + 3.8 + env.reg.getWarnings().warn(new String(chars, p, end) + 3.9 " redundant nested repeat operator"); 3.10 break; 3.11 3.12 default: 3.13 - env.reg.warnings.warn(new String(chars, p, end) + 3.14 + env.reg.getWarnings().warn(new String(chars, p, end) + 3.15 " nested repeat operator " + Reduce.PopularQStr[targetQNum] + 3.16 " and " + Reduce.PopularQStr[nestQNum] + " was replaced with '" + 3.17 Reduce.ReduceQStr[Reduce.REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");