[jruby-joni] 144/194: remove hard reference to root

Hideki Yamane henrich at moszumanska.debian.org
Thu Feb 1 12:04:35 UTC 2018


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit dc6b39f565aa7e770e964f802fe2d86e24c5e9b8
Author: lopex <lopx at gazeta.pl>
Date:   Thu Jan 11 11:28:38 2018 +0100

    remove hard reference to root
---
 src/org/joni/Analyser.java | 29 ++++++++---------------------
 src/org/joni/Compiler.java |  4 ++--
 src/org/joni/Parser.java   | 10 +---------
 3 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index 2ddeb63..8a65d02 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -61,10 +61,7 @@ final class Analyser extends Parser {
     }
 
     protected final void compile() {
-        if (Config.DEBUG) {
-            Config.log.println(regex.encStringToString(bytes, getBegin(), getEnd()));
-        }
-
+        if (Config.DEBUG) Config.log.println(regex.encStringToString(bytes, getBegin(), getEnd()));
         reset();
 
         regex.numMem = 0;
@@ -77,7 +74,9 @@ final class Analyser extends Parser {
 
         if (Config.USE_CEC) regex.numCombExpCheck = 0;
 
-        parse();
+
+        Node root = parseRegexp(); // onig_parse_make_tree
+        regex.numMem = env.numMem;
 
         if (Config.USE_NAMED_GROUP) {
             /* mixed use named group and no-named group */
@@ -155,8 +154,7 @@ final class Analyser extends Parser {
 
         env.memNodes = null;
 
-        new ArrayCompiler(this).compile();
-        //new AsmCompiler(this).compile();
+        new ArrayCompiler(this).compile(root);
 
         if (regex.numRepeat != 0 || regex.btMemEnd != 0) {
             regex.stackPopLevel = StackPopLevel.ALL;
@@ -173,7 +171,6 @@ final class Analyser extends Parser {
             Config.log.println("stack used: " + regex.requireStack);
             if (Config.USE_STRING_TEMPLATES) Config.log.print("templates: " + regex.templateNum + "\n");
             Config.log.println(new ByteCodePrinter(regex).byteCodeListToString());
-
         } // DEBUG_COMPILE
     }
 
@@ -332,16 +329,6 @@ final class Analyser extends Parser {
         return root;
     }
 
-    private void swap(Node a, Node b) {
-        a.swap(b);
-
-        if (root == b) {
-            root = a;
-        } else if (root == a) {
-            root = b;
-        }
-    }
-
     // USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK
     private int quantifiersMemoryInfo(Node node) {
         int info = 0;
@@ -1359,7 +1346,7 @@ final class Analyser extends Parser {
         Node head = an.target;
         Node np = ((ListNode)head).value;
 
-        swap(node, head);
+        node.swap(head);
 
         Node tmp = node;
         node = head;
@@ -1429,7 +1416,7 @@ final class Analyser extends Parser {
                                 EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); //onig_node_new_enclose
                                 en.setStopBtSimpleRepeat();
                                 //en.setTarget(qn.target); // optimize it ??
-                                swap(node, en);
+                                node.swap(en);
 
                                 en.setTarget(node);
                             }
@@ -1670,7 +1657,7 @@ final class Analyser extends Parser {
         /* ending */
         Node xnode = topRoot != null ? topRoot : prevNode.p;
 
-        swap(node, xnode);
+        node.swap(xnode);
         return xnode;
     }
 
diff --git a/src/org/joni/Compiler.java b/src/org/joni/Compiler.java
index bd2d9ad..4e6777b 100644
--- a/src/org/joni/Compiler.java
+++ b/src/org/joni/Compiler.java
@@ -46,9 +46,9 @@ abstract class Compiler implements ErrorMessages {
         this.enc = regex.enc;
     }
 
-    final void compile() {
+    final void compile(Node root) {
         prepare();
-        compileTree(analyser.root);
+        compileTree(root);
         finish();
     }
 
diff --git a/src/org/joni/Parser.java b/src/org/joni/Parser.java
index 20b3f1e..94cf804 100644
--- a/src/org/joni/Parser.java
+++ b/src/org/joni/Parser.java
@@ -52,7 +52,6 @@ import org.joni.constants.TokenType;
 
 class Parser extends Lexer {
     protected final Regex regex;
-    protected Node root;
     protected int returnCode; // return code used by parser methods (they itself return parsed nodes)
                               // this approach will not affect recursive calls
 
@@ -61,13 +60,6 @@ class Parser extends Lexer {
         this.regex = regex;
     }
 
-    // onig_parse_make_tree
-    protected final Node parse() {
-        root = parseRegexp();
-        regex.numMem = env.numMem;
-        return root;
-    }
-
     private static final int POSIX_BRACKET_NAME_MIN_LEN            = 4;
     private static final int POSIX_BRACKET_CHECK_LIMIT_LENGTH      = 20;
     private static final byte BRACKET_END[]                        = ":]".getBytes();
@@ -1603,7 +1595,7 @@ class Parser extends Lexer {
         }
     }
 
-    private Node parseRegexp() {
+    protected final Node parseRegexp() {
         fetchToken();
         Node top = parseSubExp(TokenType.EOT);
         if (Config.USE_SUBEXP_CALL) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list