changeset 2509:2f5ad880fd33 jdk8u252-b09 jdk8u252-ga

8223904: Improve Nashorn matching Reviewed-by: jlaskey, sundar, mschoene, rhalade
author hannesw
date Fri, 15 Nov 2019 19:10:43 +0100
parents 2e03a91e04b9
children a805f6863c1c
files src/jdk/nashorn/internal/runtime/regexp/joni/Parser.java src/jdk/nashorn/internal/runtime/regexp/joni/ast/StringNode.java
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/Parser.java	Wed Nov 06 17:13:21 2019 +0100
+++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Parser.java	Fri Nov 15 19:10:43 2019 +0100
@@ -452,7 +452,7 @@
     private Node parseExp(final TokenType term) {
         if (token.type == term)
          {
-            return StringNode.EMPTY; // goto end_of_token
+            return StringNode.createEmpty(); // goto end_of_token
         }
 
         Node node = null;
@@ -461,7 +461,7 @@
         switch(token.type) {
         case ALT:
         case EOT:
-            return StringNode.EMPTY; // end_of_token:, node_new_empty
+            return StringNode.createEmpty(); // end_of_token:, node_new_empty
 
         case SUBEXP_OPEN:
             node = parseEnclose(TokenType.SUBEXP_CLOSE);
@@ -569,7 +569,7 @@
                 if (syntax.contextInvalidRepeatOps()) {
                     throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED);
                 }
-                node = StringNode.EMPTY; // node_new_empty
+                node = StringNode.createEmpty(); // node_new_empty
             } else {
                 return parseExpTkByte(group); // goto tk_byte
             }
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/ast/StringNode.java	Wed Nov 06 17:13:21 2019 +0100
+++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ast/StringNode.java	Fri Nov 15 19:10:43 2019 +0100
@@ -27,7 +27,6 @@
 
     private static final int NODE_STR_MARGIN = 16;
     private static final int NODE_STR_BUF_SIZE = 24;
-    public static final StringNode EMPTY = new StringNode(null, Integer.MAX_VALUE, Integer.MAX_VALUE);
 
     public char[] chars;
     public int p;
@@ -36,7 +35,13 @@
     public int flag;
 
     public StringNode() {
-        this.chars = new char[NODE_STR_BUF_SIZE];
+        this(NODE_STR_BUF_SIZE);
+    }
+
+    private StringNode(int size) {
+        this.chars = new char[size];
+        this.p = 0;
+        this.end = 0;
     }
 
     public StringNode(final char[] chars, final int p, final int end) {
@@ -51,6 +56,13 @@
         chars[end++] = c;
     }
 
+    /**
+     * Create a new empty StringNode.
+     */
+    public static StringNode createEmpty() {
+        return new StringNode(0);
+    }
+
     /* Ensure there is ahead bytes available in node's buffer
      * (assumes that the node is not shared)
      */