[jruby-joni] 114/279: Make OPCode.EXACTN_IC, OPCode.EXACTN_IC_SB use string templates as well.

Hideki Yamane henrich at moszumanska.debian.org
Mon Nov 16 11:27:08 UTC 2015


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 2b108024033385c32a674b8c460f93a7b5da6712
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date:   Mon Feb 20 01:33:03 2012 +0100

    Make OPCode.EXACTN_IC, OPCode.EXACTN_IC_SB use string templates as well.
---
 src/org/joni/Analyser.java        |  2 +-
 src/org/joni/ArrayCompiler.java   |  2 +-
 src/org/joni/ByteCodeMachine.java | 63 +++++++++++++++++++++++++++++----------
 src/org/joni/ByteCodePrinter.java | 12 ++++++--
 4 files changed, 60 insertions(+), 19 deletions(-)

diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index b8995ce..7b03ec2 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -172,7 +172,7 @@ final class Analyser extends Parser {
         if (Config.DEBUG_COMPILE) {
             if (Config.USE_NAMED_GROUP) Config.log.print(regex.nameTableToString());
             Config.log.println("stack used: " + regex.stackNeeded);
-            if (Config.USE_STRING_TEMPLATES) Config.log.print("  templates: " + regex.templateNum);
+            if (Config.USE_STRING_TEMPLATES) Config.log.print("templates: " + regex.templateNum + "\n");
             Config.log.println(new ByteCodePrinter(regex).byteCodeListToString());
 
         } // DEBUG_COMPILE
diff --git a/src/org/joni/ArrayCompiler.java b/src/org/joni/ArrayCompiler.java
index f863a3f..6ac7429 100644
--- a/src/org/joni/ArrayCompiler.java
+++ b/src/org/joni/ArrayCompiler.java
@@ -106,7 +106,7 @@ final class ArrayCompiler extends Compiler {
     }
 
     private boolean opTemplated(int op) {
-        return op == OPCode.EXACTN || op == OPCode.EXACTMB2N;
+        return op == OPCode.EXACTN || op == OPCode.EXACTMB2N || op == OPCode.EXACTN_IC || op == OPCode.EXACTN_IC_SB;
     }
 
     private int selectStrOpcode(int mbLength, int strLength, boolean ignoreCase) {
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index f36a2ce..1c78909 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -605,32 +605,65 @@ class ByteCodeMachine extends StackMachine {
 
     private void opExactNIC() {
         int tlen = code[ip++];
-        int endp = ip + tlen;
-
         byte[]lowbuf = cfbuf();
 
-        while (ip < endp) {
-            sprev = s;
-            if (s >= range) {opFail(); return;}
+        if (Config.USE_STRING_TEMPLATES) {
+            byte[]bs = regex.templates[code[ip++]];
+            int ps = code[ip++];
+            int endp = ps + tlen;
 
-            value = s;
-            int len = enc.mbcCaseFold(regex.caseFoldFlag, bytes, this, end, lowbuf);
-            s = value;
+            while (ps < endp) {
+                sprev = s;
+                if (s >= range) {opFail(); return;}
+
+                value = s;
+                int len = enc.mbcCaseFold(regex.caseFoldFlag, bytes, this, end, lowbuf);
+                s = value;
+
+                if (s > range) {opFail(); return;}
+                int q = 0;
+                while (len-- > 0) {
+                    if (bs[ps] != lowbuf[q]) {opFail(); return;}
+                    ps++; q++;
+                }
+            }
+        } else {
+            int endp = ip + tlen;
 
-            if (s > range) {opFail(); return;}
-            int q = 0;
-            while (len-- > 0) {
-                if (code[ip] != lowbuf[q]) {opFail(); return;}
-                ip++; q++;
+            while (ip < endp) {
+                sprev = s;
+                if (s >= range) {opFail(); return;}
+
+                value = s;
+                int len = enc.mbcCaseFold(regex.caseFoldFlag, bytes, this, end, lowbuf);
+                s = value;
+
+                if (s > range) {opFail(); return;}
+                int q = 0;
+                while (len-- > 0) {
+                    if (code[ip] != lowbuf[q]) {opFail(); return;}
+                    ip++; q++;
+                }
             }
         }
+
     }
 
     private void opExactNICSb() {
         int tlen = code[ip++];
         if (s + tlen > range) {opFail(); return;}
-        byte[]toLowerTable = enc.toLowerCaseTable();
-        while (tlen-- > 0) if (code[ip++] != toLowerTable[bytes[s++] & 0xff]) {opFail(); return;}
+
+        if (Config.USE_STRING_TEMPLATES) {
+            byte[]bs = regex.templates[code[ip++]];
+            int ps = code[ip++];
+            byte[]toLowerTable = enc.toLowerCaseTable();
+            while (tlen-- > 0) if (bs[ps++] != toLowerTable[bytes[s++] & 0xff]) {opFail(); return;}
+
+        } else {
+            byte[]toLowerTable = enc.toLowerCaseTable();
+            while (tlen-- > 0) if (code[ip++] != toLowerTable[bytes[s++] & 0xff]) {opFail(); return;}
+
+        }
         sprev = s - 1;
     }
 
diff --git a/src/org/joni/ByteCodePrinter.java b/src/org/joni/ByteCodePrinter.java
index 4cddca3..6c95149 100644
--- a/src/org/joni/ByteCodePrinter.java
+++ b/src/org/joni/ByteCodePrinter.java
@@ -224,8 +224,16 @@ class ByteCodePrinter {
             case OPCode.EXACTN_IC_SB:
                 len = code[bp];
                 bp += OPSize.LENGTH;
-                pLenString(sb, len, 1, bp);
-                bp += len;
+                if (Config.USE_STRING_TEMPLATES) {
+                    tm = code[bp];
+                    bp += OPSize.INDEX;
+                    idx = code[bp];
+                    bp += OPSize.INDEX;
+                    pLenStringFromTemplate(sb, len, 1, templates[tm], idx);
+                } else {
+                    pLenString(sb, len, 1, bp);
+                    bp += len;
+                }
                 break;
 
             case OPCode.CCLASS:

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