[jruby-joni] 37/194: remove shared char class logic

Hideki Yamane henrich at moszumanska.debian.org
Thu Feb 1 12:04:18 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 a3656b6a629713d7296644dcf0cecba5a706d7df
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date:   Wed Dec 27 14:02:05 2017 +0100

    remove shared char class logic
---
 src/org/joni/ArrayCompiler.java    | 24 ------------
 src/org/joni/ByteCodeMachine.java  | 17 +--------
 src/org/joni/ByteCodePrinter.java  | 18 +--------
 src/org/joni/Config.java           |  1 -
 src/org/joni/Parser.java           |  1 -
 src/org/joni/Regex.java            |  3 --
 src/org/joni/ast/CClassNode.java   | 77 +-------------------------------------
 src/org/joni/constants/OPCode.java | 17 +++------
 8 files changed, 9 insertions(+), 149 deletions(-)

diff --git a/src/org/joni/ArrayCompiler.java b/src/org/joni/ArrayCompiler.java
index c5f0c38..88f1e0e 100644
--- a/src/org/joni/ArrayCompiler.java
+++ b/src/org/joni/ArrayCompiler.java
@@ -270,8 +270,6 @@ final class ArrayCompiler extends Compiler {
     }
 
     private int compileLengthCClassNode(CClassNode cc) {
-        if (cc.isShare()) return OPSize.OPCODE + OPSize.POINTER;
-
         int len;
         if (cc.mbuf == null) {
             len = OPSize.OPCODE + BitSet.BITSET_SIZE;
@@ -289,12 +287,6 @@ final class ArrayCompiler extends Compiler {
 
     @Override
     protected void compileCClassNode(CClassNode cc) {
-        if (cc.isShare()) { // shared char class
-            addOpcode(OPCode.CCLASS_NODE);
-            addPointer(cc);
-            return;
-        }
-
         if (cc.mbuf == null) {
             if (cc.isNot()) {
                 addOpcode(enc.isSingleByte() ? OPCode.CCLASS_NOT_SB : OPCode.CCLASS_NOT);
@@ -1206,18 +1198,6 @@ final class ArrayCompiler extends Compiler {
         regex.code[offset] = i;
     }
 
-    private void addObject(Object o) {
-        if (regex.operands == null) {
-            regex.operands = new Object[4];
-        } else if (regex.operandLength >= regex.operands.length) {
-            Object[]tmp = new Object[regex.operands.length << 1];
-            System.arraycopy(regex.operands, 0, tmp, 0, regex.operands.length);
-            regex.operands = tmp;
-        }
-        addInt(regex.operandLength);
-        regex.operands[regex.operandLength++] = o;
-    }
-
     private void addBytes(byte[]bytes, int p ,int length) {
         ensure(codeLength + length);
         int end = p + length;
@@ -1255,10 +1235,6 @@ final class ArrayCompiler extends Compiler {
         addInt(num);
     }
 
-    private void addPointer(Object o) {
-        addObject(o);
-    }
-
     private void addOption(int option) {
         addInt(option);
     }
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index e42e9e7..10dc26e 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -224,8 +224,7 @@ class ByteCodeMachine extends StackMachine {
                 case OPCode.CCLASS_NOT:                 opCClassNot();             break;
                 case OPCode.CCLASS_MB_NOT:              opCClassMBNot();           break;
                 case OPCode.CCLASS_MIX_NOT:             opCClassMIXNot();          break;
-                case OPCode.CCLASS_NODE:                opCClassNode();            break;
-
+                case OPCode.LOOK_BEHIND_SB:             opLookBehindSb();          continue;
                 case OPCode.ANYCHAR:                    opAnyChar();               break;
                 case OPCode.ANYCHAR_ML:                 opAnyCharML();             break;
                 case OPCode.ANYCHAR_STAR:               opAnyCharStar();           break;
@@ -324,8 +323,6 @@ class ByteCodeMachine extends StackMachine {
                 case OPCode.WORD_BEGIN_SB:                  opWordBeginSb();             continue;
                 case OPCode.WORD_END_SB:                    opWordEndSb();               continue;
 
-                case OPCode.LOOK_BEHIND_SB:                 opLookBehindSb();            continue;
-
                 case OPCode.EXACT1_IC_SB:                   opExact1ICSb();              break;
                 case OPCode.EXACTN_IC_SB:                   opExactNICSb();              continue;
                 case OPCode.CONDITION:                      opCondition();               continue;
@@ -831,18 +828,6 @@ class ByteCodeMachine extends StackMachine {
         sprev = sbegin; // break;
     }
 
-    private void opCClassNode() {
-        if (s >= range) {opFail(); return;}
-        CClassNode cc = (CClassNode)regex.operands[code[ip++]];
-        int mbLen = enc.length(bytes, s, end);
-        int ss = s;
-        s += mbLen;
-        if (s > range) {opFail(); return;}
-        int c = enc.mbcToCode(bytes, ss, s);
-        if (!cc.isCodeInCCLength(mbLen, c)) {opFail(); return;}
-        sprev = sbegin; // break;
-    }
-
     private void opAnyChar() {
         if (s >= range) {opFail(); return;}
         int n = enc.length(bytes, s, end);
diff --git a/src/org/joni/ByteCodePrinter.java b/src/org/joni/ByteCodePrinter.java
index 8bb1e6c..66b489e 100644
--- a/src/org/joni/ByteCodePrinter.java
+++ b/src/org/joni/ByteCodePrinter.java
@@ -30,18 +30,12 @@ class ByteCodePrinter {
     final int[]code;
     final int codeLength;
     final byte[][] templates;
-
-    Object[]operands;
-    int operantCount;
-    Encoding enc;
-    WarnCallback warnings;
+    final Encoding enc;
+    final WarnCallback warnings;
 
     public ByteCodePrinter(Regex regex) {
         code = regex.code;
         codeLength = regex.codeLength;
-        operands = regex.operands;
-        operantCount = regex.operandLength;
-
         templates = regex.templates;
         enc = regex.enc;
         warnings = regex.warnings;
@@ -71,7 +65,6 @@ class ByteCodePrinter {
     public int compiledByteCodeToString(StringBuilder sb, int bp) {
         int len, n, mem, addr, scn, cod;
         BitSet bs;
-        CClassNode cc;
         int tm, idx;
 
         sb.append("[" + OPCode.OpCodeNames[code[bp]]);
@@ -292,13 +285,6 @@ class ByteCodePrinter {
                 sb.append(":" + n + ":" + cod + ":" + len);
                 break;
 
-            case OPCode.CCLASS_NODE:
-                cc = (CClassNode)operands[code[bp]];
-                bp += OPSize.POINTER;
-                n = cc.bs.numOn();
-                sb.append(":" + cc + ":" + n);
-                break;
-
             case OPCode.BACKREFN_IC:
                 mem = code[bp];
                 bp += OPSize.MEMNUM;
diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java
index 11a0e73..6802817 100644
--- a/src/org/joni/Config.java
+++ b/src/org/joni/Config.java
@@ -56,7 +56,6 @@ public interface Config extends org.jcodings.Config {
     // internal config
     final boolean USE_PARSE_TREE_NODE_RECYCLE       = true;
     final boolean USE_OP_PUSH_OR_JUMP_EXACT         = true;
-    final boolean USE_SHARED_CCLASS_TABLE			= false;
     final boolean USE_QTFR_PEEK_NEXT                = true;
 
     final int INIT_MATCH_STACK_SIZE                 = 64;
diff --git a/src/org/joni/Parser.java b/src/org/joni/Parser.java
index cbd8267..47c3aa0 100644
--- a/src/org/joni/Parser.java
+++ b/src/org/joni/Parser.java
@@ -1376,7 +1376,6 @@ class Parser extends Lexer {
         case CharacterType.SPACE:
         case CharacterType.DIGIT:
         case CharacterType.XDIGIT:
-            // #ifdef USE_SHARED_CCLASS_TABLE ... #endif
             CClassNode ccn = new CClassNode();
             ccn.addCType(token.getPropCType(), false, env, this);
             if (token.getPropNot()) ccn.setNot();
diff --git a/src/org/joni/Regex.java b/src/org/joni/Regex.java
index 3b77a3a..5edb88c 100644
--- a/src/org/joni/Regex.java
+++ b/src/org/joni/Regex.java
@@ -36,12 +36,9 @@ import org.joni.exception.InternalException;
 import org.joni.exception.ValueException;
 
 public final class Regex {
-
     int[] code;             /* compiled pattern */
     int codeLength;
     boolean requireStack;
-    Object[]operands;       /* e.g. shared CClassNode */
-    int operandLength;
 
     int numMem;             /* used memory(...) num counted from 1 */
     int numRepeat;          /* OP_REPEAT/OP_REPEAT_NG id-counter */
diff --git a/src/org/joni/ast/CClassNode.java b/src/org/joni/ast/CClassNode.java
index ef0aadd..5bfe05a 100644
--- a/src/org/joni/ast/CClassNode.java
+++ b/src/org/joni/ast/CClassNode.java
@@ -35,54 +35,21 @@ import org.joni.exception.SyntaxException;
 import org.joni.exception.ValueException;
 
 public final class CClassNode extends Node {
-    private static final int FLAG_NCCLASS_NOT = 1<<0;
-    private static final int FLAG_NCCLASS_SHARE = 1<<1;
+    private static final int FLAG_NCCLASS_NOT = 1 << 0;
 
     int flags;
     public final BitSet bs = new BitSet();  // conditional creation ?
     public CodeRangeBuffer mbuf;            /* multi-byte info or NULL */
 
-    private int ctype;                      // for hashing purposes
-    private Encoding enc;                   // ...
-
-
     // node_new_cclass
     public CClassNode() {}
 
-    public CClassNode(int ctype, Encoding enc, boolean not, int sbOut, int[]ranges) {
-        this(not, sbOut, ranges);
-        this.ctype = ctype;
-        this.enc = enc;
-    }
-
     public void clear() {
         bs.clear();
         flags = 0;
         mbuf = null;
     }
 
-    // node_new_cclass_by_codepoint_range, only used by shared Char Classes
-    public CClassNode(boolean not, int sbOut, int[]ranges) {
-        if (not) setNot();
-        // bs.clear();
-
-        if (sbOut > 0 && ranges != null) {
-            int n = ranges[0];
-            for (int i=0; i<n; i++) {
-                int from = ranges[i * 2 + 1];
-                int to = ranges[i * 2 + 2];
-                for (int j=from; j<=to; j++) {
-                    if (j >= sbOut) {
-                        setupBuffer(ranges);
-                        return;
-                    }
-                    bs.set(j);
-                }
-            }
-        }
-        setupBuffer(ranges);
-    }
-
     @Override
     public int getType() {
         return CCLASS;
@@ -94,49 +61,20 @@ public final class CClassNode extends Node {
     }
 
     @Override
-    public boolean equals(Object other) {
-        if (!(other instanceof CClassNode)) return false;
-        CClassNode cc = (CClassNode)other;
-        return ctype == cc.ctype && isNot() == cc.isNot() && enc == cc.enc;
-    }
-
-    @Override
-    public int hashCode() {
-        if (Config.USE_SHARED_CCLASS_TABLE) {
-            int hash = 0;
-            hash += ctype;
-            hash += enc.hashCode();
-            if (isNot()) hash++;
-            return hash + (hash >> 5);
-        } else {
-            return super.hashCode();
-        }
-    }
-
-    @Override
     public String toString(int level) {
         StringBuilder value = new StringBuilder();
         value.append("\n  flags: " + flagsToString());
         value.append("\n  bs: " + pad(bs, level + 1));
         value.append("\n  mbuf: " + pad(mbuf, level + 1));
-
         return value.toString();
     }
 
     public String flagsToString() {
         StringBuilder flags = new StringBuilder();
         if (isNot()) flags.append("NOT ");
-        if (isShare()) flags.append("SHARE ");
         return flags.toString();
     }
 
-    private void setupBuffer(int[]ranges) {
-        if (ranges != null) {
-            if (ranges[0] == 0) return;
-            mbuf = new CodeRangeBuffer(ranges);
-        }
-    }
-
     public boolean isEmpty() {
         return mbuf == null && bs.isEmpty();
     }
@@ -156,7 +94,6 @@ public final class CClassNode extends Node {
     public void clearNotFlag(Encoding enc) {
         if (isNot()) {
             bs.invert();
-
             if (!enc.isSingleByte()) {
                 mbuf = CodeRangeBuffer.notCodeRangeBuff(enc, mbuf);
             }
@@ -557,18 +494,6 @@ public final class CClassNode extends Node {
         return (flags & FLAG_NCCLASS_NOT) != 0;
     }
 
-    public void setShare() {
-        flags |= FLAG_NCCLASS_SHARE;
-    }
-
-    public void clearShare() {
-        flags &= ~FLAG_NCCLASS_SHARE;
-    }
-
-    public boolean isShare() {
-        return (flags & FLAG_NCCLASS_SHARE) != 0;
-    }
-
     private static int CR_FROM(int[] range, int i) {
         return range[(i * 2) + 1];
     }
diff --git a/src/org/joni/constants/OPCode.java b/src/org/joni/constants/OPCode.java
index 06d0feb..50b653a 100644
--- a/src/org/joni/constants/OPCode.java
+++ b/src/org/joni/constants/OPCode.java
@@ -47,8 +47,7 @@ public interface OPCode {
     final int CCLASS_NOT                    = 19;
     final int CCLASS_MB_NOT                 = 20;
     final int CCLASS_MIX_NOT                = 21;
-    final int CCLASS_NODE                   = 22;           /* pointer to CClassNode node */
-
+    final int LOOK_BEHIND_SB                = 22;
     final int ANYCHAR                       = 23;           /* "."  */
     final int ANYCHAR_ML                    = 24;           /* "."  multi-line */
     final int ANYCHAR_STAR                  = 25;           /* ".*" */
@@ -155,10 +154,8 @@ public interface OPCode {
     final int WORD_BEGIN_SB                 = 110;
     final int WORD_END_SB                   = 111;
 
-    final int LOOK_BEHIND_SB                = 112;
-
-    final int EXACT1_IC_SB                  = 113;           /* single byte, N = 1, ignore case */
-    final int EXACTN_IC_SB                  = 114;           /* single byte,        ignore case */
+    final int EXACT1_IC_SB                  = 112;           /* single byte, N = 1, ignore case */
+    final int EXACTN_IC_SB                  = 113;           /* single byte,        ignore case */
 
     public final String OpCodeNames[] = Config.DEBUG_COMPILE ? new String[] {
         "finish", /*OP_FINISH*/
@@ -183,7 +180,7 @@ public interface OPCode {
         "cclass-not", /*OP_CCLASS_NOT*/
         "cclass-mb-not", /*OP_CCLASS_MB_NOT*/
         "cclass-mix-not", /*OP_CCLASS_MIX_NOT*/
-        "cclass-node", /*OP_CCLASS_NODE*/
+        "look-behind-sb", /*OP_LOOK_BEHIND*/
         "anychar", /*OP_ANYCHAR*/
         "anychar-ml", /*OP_ANYCHAR_ML*/
         "anychar*", /*OP_ANYCHAR_STAR*/
@@ -278,8 +275,6 @@ public interface OPCode {
         "word-begin-sb", /*OP_WORD_BEGIN*/
         "word-end-sb", /*OP_WORD_END*/
 
-        "look-behind-sb", /*OP_LOOK_BEHIND*/
-
         "exact1-ic-sb", /*OP_EXACT1_IC*/
         "exactn-ic-sb", /*OP_EXACTN_IC*/
 
@@ -308,7 +303,7 @@ public interface OPCode {
         Arguments.SPECIAL, /*OP_CCLASS_NOT*/
         Arguments.SPECIAL, /*OP_CCLASS_MB_NOT*/
         Arguments.SPECIAL, /*OP_CCLASS_MIX_NOT*/
-        Arguments.SPECIAL, /*OP_CCLASS_NODE*/
+        Arguments.SPECIAL, /*OP_LOOK_BEHIND*/
         Arguments.NON, /*OP_ANYCHAR*/
         Arguments.NON, /*OP_ANYCHAR_ML*/
         Arguments.NON, /*OP_ANYCHAR_STAR*/
@@ -403,8 +398,6 @@ public interface OPCode {
         Arguments.NON, /*OP_WORD_BEGIN*/
         Arguments.NON, /*OP_WORD_END*/
 
-        Arguments.SPECIAL, /*OP_LOOK_BEHIND*/
-
         Arguments.SPECIAL, /*OP_EXACT1_IC*/
         Arguments.SPECIAL, /*OP_EXACTN_IC*/
     } : null;

-- 
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