Skip to content

Instantly share code, notes, and snippets.

@enebo
Created July 24, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enebo/ef854d4f4929c5484660aa6453e99b2c to your computer and use it in GitHub Desktop.
Save enebo/ef854d4f4929c5484660aa6453e99b2c to your computer and use it in GitHub Desktop.
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index 218d0e8..980d4f0 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -52,8 +52,8 @@ class ByteCodeMachine extends StackMachine {
private final int[]code; // byte code
private int ip; // instruction pointer
- ByteCodeMachine(Regex regex, byte[]bytes, int p, int end) {
- super(regex, bytes, p, end);
+ ByteCodeMachine(Regex regex, byte[]bytes, int p, int end, boolean makeRegions) {
+ super(regex, bytes, p, end, makeRegions);
this.code = regex.code;
}
diff --git a/src/org/joni/Matcher.java b/src/org/joni/Matcher.java
index c4226fd..2d99f81 100644
--- a/src/org/joni/Matcher.java
+++ b/src/org/joni/Matcher.java
@@ -48,6 +48,16 @@ public abstract class Matcher extends IntHolder {
protected int msaBegin;
protected int msaEnd;
+ Matcher(Regex regex, byte[]bytes, int p, int end, boolean makeRegions) {
+ this.regex = regex;
+ this.enc = regex.enc;
+ this.bytes = bytes;
+ this.str = p;
+ this.end = end;
+
+ this.msaRegion = (!makeRegions || regex.numMem == 0) ? null : new Region(regex.numMem + 1);
+ }
+
Matcher(Regex regex, byte[]bytes, int p, int end) {
this.regex = regex;
this.enc = regex.enc;
diff --git a/src/org/joni/MatcherFactory.java b/src/org/joni/MatcherFactory.java
index 7d12215..fa41230 100644
--- a/src/org/joni/MatcherFactory.java
+++ b/src/org/joni/MatcherFactory.java
@@ -21,11 +21,17 @@ package org.joni;
abstract class MatcherFactory {
abstract Matcher create(Regex regex, byte[]bytes, int p, int end);
+ abstract Matcher createNoRegions(Regex regex, byte[]bytes, int p, int end);
static final MatcherFactory DEFAULT = new MatcherFactory() {
@Override
Matcher create(Regex regex, byte[] bytes, int p, int end) {
- return new ByteCodeMachine(regex, bytes, p, end);
+ return new ByteCodeMachine(regex, bytes, p, end, true);
+ }
+
+ @Override
+ Matcher createNoRegions(Regex regex, byte[] bytes, int p, int end) {
+ return new ByteCodeMachine(regex, bytes, p, end, false);
}
};
}
diff --git a/src/org/joni/Regex.java b/src/org/joni/Regex.java
index c900ed3..71d457d 100644
--- a/src/org/joni/Regex.java
+++ b/src/org/joni/Regex.java
@@ -160,6 +160,10 @@ public final class Regex {
return factory.create(this, bytes, p, end);
}
+ public Matcher matcherNoRegions(byte[]bytes, int p, int end) {
+ return factory.createNoRegions(this, bytes, p, end);
+ }
+
public int numberOfCaptures() {
return numMem;
}
diff --git a/src/org/joni/StackMachine.java b/src/org/joni/StackMachine.java
index 73835f8..5f6b00a 100644
--- a/src/org/joni/StackMachine.java
+++ b/src/org/joni/StackMachine.java
@@ -38,8 +38,8 @@ abstract class StackMachine extends Matcher implements StackType {
protected byte[] stateCheckBuff; // CEC, move to int[] ?
protected int stateCheckBuffSize;
- protected StackMachine(Regex regex, byte[]bytes, int p , int end) {
- super(regex, bytes, p, end);
+ protected StackMachine(Regex regex, byte[]bytes, int p , int end, boolean makeRegions) {
+ super(regex, bytes, p, end, makeRegions);
stack = regex.requireStack ? fetchStack() : null;
final int n;
if (Config.USE_SUBEXP_CALL) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment