8011884: Regexp literals are compiled twice
authorhannesw
Fri, 12 Apr 2013 16:31:16 +0200
changeset 16944 7c9a4d480d39
parent 16943 a1b9b7970813
child 16945 89cbe9510278
8011884: Regexp literals are compiled twice Reviewed-by: lagergren, sundar
nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java
nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java	Thu Apr 11 12:16:39 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java	Fri Apr 12 16:31:16 2013 +0200
@@ -156,9 +156,6 @@
 
         env.memNodes = null;
 
-        new ArrayCompiler(this).compile();
-        //new AsmCompiler(this).compile();
-
         if (regex.numRepeat != 0 || regex.btMemEnd != 0) {
             regex.stackPopLevel = StackPopLevel.ALL;
         } else {
--- a/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java	Thu Apr 11 12:16:39 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java	Fri Apr 12 16:31:16 2013 +0200
@@ -55,8 +55,9 @@
     int[]repeatRangeLo;
     int[]repeatRangeHi;
 
-    public WarnCallback warnings;
-    public MatcherFactory factory;
+    WarnCallback warnings;
+    MatcherFactory factory;
+    private Analyser analyser;
 
     int options;
     int userOptions;
@@ -140,19 +141,33 @@
         this.caseFoldFlag = caseFoldFlag;
         this.warnings = warnings;
 
-        new Analyser(new ScanEnvironment(this, syntax), chars, p, end).compile();
+        this.analyser = new Analyser(new ScanEnvironment(this, syntax), chars, p, end);
+        this.analyser.compile();
 
         this.warnings = null;
     }
 
+    public void compile() {
+        if (factory == null && analyser != null) {
+            Compiler compiler = new ArrayCompiler(analyser);
+            analyser = null; // only do this once
+            compiler.compile();
+        }
+    }
+
     public Matcher matcher(char[] chars) {
         return matcher(chars, 0, chars.length);
     }
 
     public Matcher matcher(char[] chars, int p, int end) {
+        compile();
         return factory.create(this, chars, p, end);
     }
 
+    public WarnCallback getWarnings() {
+        return warnings;
+    }
+
     public int numberOfCaptures() {
         return numMem;
     }
--- a/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java	Thu Apr 11 12:16:39 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java	Fri Apr 12 16:31:16 2013 +0200
@@ -231,12 +231,12 @@
                         break;
 
                     case DEL:
-                        env.reg.warnings.warn(new String(chars, p, end) +
+                        env.reg.getWarnings().warn(new String(chars, p, end) +
                                 " redundant nested repeat operator");
                         break;
 
                     default:
-                        env.reg.warnings.warn(new String(chars, p, end) +
+                        env.reg.getWarnings().warn(new String(chars, p, end) +
                                 " nested repeat operator " + Reduce.PopularQStr[targetQNum] +
                                 " and " + Reduce.PopularQStr[nestQNum] + " was replaced with '" +
                                 Reduce.ReduceQStr[Reduce.REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");