Created
May 20, 2016 07:08
-
-
Save headius/d30b0db212d89e81726dc5f336b9e7be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java | |
index 5cf643e..f02c013 100644 | |
--- a/src/org/joni/ByteCodeMachine.java | |
+++ b/src/org/joni/ByteCodeMachine.java | |
@@ -36,6 +36,8 @@ import org.joni.constants.OPSize; | |
import org.joni.exception.ErrorMessages; | |
import org.joni.exception.InternalException; | |
+import java.util.Arrays; | |
+ | |
class ByteCodeMachine extends StackMachine { | |
private static final int INTERRUPT_CHECK_EVERY = 30000; | |
int interruptCheckCounter = 0; // we modulos this to occasionally check for interrupts | |
@@ -56,6 +58,21 @@ class ByteCodeMachine extends StackMachine { | |
this.code = regex.code; | |
} | |
+// @Override | |
+// public void clear(int begin, int end) { | |
+// super.clear(begin, end); | |
+// bestLen = 0; | |
+// s = 0; | |
+// range = 0; | |
+// sprev = 0; | |
+// sstart = 0; | |
+// sbegin = 0; | |
+// ip = 0; | |
+// stkp = 0; | |
+// if (cfbuf != null) Arrays.fill(cfbuf, (byte) 0); | |
+// if (cfbuf2 != null) Arrays.fill(cfbuf2, (byte) 0); | |
+// } | |
+ | |
protected int stkp; // a temporary | |
private boolean makeCaptureHistoryTree(CaptureTreeNode node) { | |
//CaptureTreeNode child; | |
diff --git a/src/org/joni/Matcher.java b/src/org/joni/Matcher.java | |
index 5b623fe..c48e724 100644 | |
--- a/src/org/joni/Matcher.java | |
+++ b/src/org/joni/Matcher.java | |
@@ -34,8 +34,8 @@ public abstract class Matcher extends IntHolder { | |
protected final Encoding enc; | |
protected final byte[]bytes; | |
- protected final int str; | |
- protected final int end; | |
+ protected int str; | |
+ protected int end; | |
protected int msaStart; | |
protected int msaOptions; | |
@@ -83,6 +83,25 @@ public abstract class Matcher extends IntHolder { | |
return msaEnd; | |
} | |
+ public final Regex getRegex() { | |
+ return regex; | |
+ } | |
+ | |
+ public final byte[] getBytes() { | |
+ return bytes; | |
+ } | |
+ | |
+ public void clear(int begin, int end) { | |
+ if (msaRegion != null) msaRegion.clear(); | |
+ msaBegin = 0; | |
+ msaBestLen = 0; | |
+ msaBestS = 0; | |
+ msaEnd = 0; | |
+ msaOptions = 0; | |
+ this.str = begin; | |
+ this.end = end; | |
+ } | |
+ | |
protected final void msaInit(int option, int start) { | |
msaOptions = option; | |
msaStart = start; | |
diff --git a/src/org/joni/StackMachine.java b/src/org/joni/StackMachine.java | |
index 07e5e04..ed6a641 100644 | |
--- a/src/org/joni/StackMachine.java | |
+++ b/src/org/joni/StackMachine.java | |
@@ -59,6 +59,15 @@ abstract class StackMachine extends Matcher implements StackType { | |
return stack; | |
} | |
+// @Override | |
+// public void clear(int begin, int end) { | |
+// super.clear(begin, end); | |
+//// stk = 0; | |
+//// if (repeatStk != null) Arrays.fill(repeatStk, 0); | |
+//// if (regex.requireStack) stack = allocateStack(); | |
+//// stateCheckBuffClear(); | |
+// } | |
+ | |
private void doubleStack() { | |
StackEntry[] newStack = new StackEntry[stack.length << 1]; | |
System.arraycopy(stack, 0, newStack, 0, stack.length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit fd7181942628c63d7759ec98f04e743933829018 | |
Merge: d706786 2478eb0 | |
Author: Charles Oliver Nutter <headius@headius.com> | |
Date: Thu May 19 16:42:25 2016 -0500 | |
WIP on master: d706786 Provide jruby.home to Surefire to get a proper home. | |
diff --cc core/pom.rb | |
index f277085,f277085..1ad4d35 | |
--- a/core/pom.rb | |
+++ b/core/pom.rb | |
@@@ -53,7 -53,7 +53,7 @@@ project 'JRuby Core' d | |
jar 'com.github.jnr:jffi:${jffi.version}' | |
jar 'com.github.jnr:jffi:${jffi.version}:native' | |
-- jar 'org.jruby.joni:joni:2.1.10' | |
++ jar 'org.jruby.joni:joni:2.1.11-SNAPSHOT' | |
jar 'org.jruby.extras:bytelist:1.0.13' | |
jar 'org.jruby.jcodings:jcodings:1.0.17' | |
jar 'org.jruby:dirgra:0.3' | |
diff --cc core/pom.xml | |
index 633086c,633086c..fea71b1 | |
--- a/core/pom.xml | |
+++ b/core/pom.xml | |
@@@ -174,7 -174,7 +174,7 @@@ DO NOT MODIFIY - GENERATED COD | |
<dependency> | |
<groupId>org.jruby.joni</groupId> | |
<artifactId>joni</artifactId> | |
-- <version>2.1.10</version> | |
++ <version>2.1.11-SNAPSHOT</version> | |
</dependency> | |
<dependency> | |
<groupId>org.jruby.extras</groupId> | |
diff --cc core/src/main/java/org/jruby/ext/strscan/RubyStringScanner.java | |
index ba4aa98,ba4aa98..996b4e6 | |
--- a/core/src/main/java/org/jruby/ext/strscan/RubyStringScanner.java | |
+++ b/core/src/main/java/org/jruby/ext/strscan/RubyStringScanner.java | |
@@@ -55,6 -55,6 +55,9 @@@ import org.jruby.util.ByteList | |
import org.jruby.util.StringSupport; | |
import org.jruby.util.TypeConverter; | |
++import java.util.HashMap; | |
++import java.util.Map; | |
++ | |
import static org.jruby.runtime.Visibility.PRIVATE; | |
/** | |
@@@ -239,6 -239,6 +242,7 @@@ public class RubyStringScanner extends | |
} | |
ThreadLocal<Matcher> currentMatcher = new ThreadLocal<>(); | |
++ Map<Regex, Matcher> cachedMatchers = new HashMap<>(); | |
RubyThread.Task<RubyStringScanner, Integer> task = new RubyThread.Task<RubyStringScanner, Integer>() { | |
@Override | |
public Integer run(ThreadContext context, RubyStringScanner rubyStringScanner) throws InterruptedException { | |
@@@ -257,14 -257,14 +261,20 @@@ | |
if (!(regex instanceof RubyRegexp)) throw runtime.newTypeError("wrong argument type " + regex.getMetaClass() + " (expected Regexp)"); | |
check(); | |
-- pattern = ((RubyRegexp)regex).preparePattern(str); | |
-- | |
clearMatched(); | |
int rest = str.getByteList().getRealSize() - pos; | |
if (rest < 0) return runtime.getNil(); | |
++ pattern = ((RubyRegexp)regex).preparePattern(str); | |
++ | |
ByteList value = str.getByteList(); | |
-- Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin() + pos, value.getBegin() + value.getRealSize()); | |
++ Matcher matcher = cachedMatchers.get(pattern); | |
++ if (matcher == null || matcher.getRegex() != pattern || matcher.getBytes() != value.getUnsafeBytes()) { | |
++ matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin() + pos, value.getBegin() + value.getRealSize()); | |
++ cachedMatchers.put(pattern, matcher); | |
++ } else { | |
++ matcher.clear(value.getBegin() + pos, value.getBegin() + value.getRealSize()); | |
++ } | |
currentMatcher.set(matcher); | |
final int ret; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment