Skip to content

Commit

Permalink
ability to pass null region
Browse files Browse the repository at this point in the history
  • Loading branch information
lopex committed Jul 25, 2018
1 parent 7ba2e02 commit af9a0dd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/org/joni/ByteCodeMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, Region region, byte[]bytes, int p, int end) {
super(regex, region, bytes, p, end);
this.code = regex.code;
}

Expand Down
5 changes: 2 additions & 3 deletions src/org/joni/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ public abstract class Matcher extends IntHolder {
protected int msaBegin;
protected int msaEnd;

Matcher(Regex regex, byte[]bytes, int p, int end) {
Matcher(Regex regex, Region region, byte[]bytes, int p, int end) {
this.regex = regex;
this.enc = regex.enc;
this.bytes = bytes;
this.str = p;
this.end = end;

this.msaRegion = regex.numMem == 0 ? null : new Region(regex.numMem + 1);
this.msaRegion = region;
}

// main matching method
Expand Down
6 changes: 3 additions & 3 deletions src/org/joni/MatcherFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package org.joni;

abstract class MatcherFactory {
abstract Matcher create(Regex regex, byte[]bytes, int p, int end);
abstract Matcher create(Regex regex, Region region, 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);
Matcher create(Regex regex, Region region, byte[]bytes, int p, int end) {
return new ByteCodeMachine(regex, region, bytes, p, end);
}
};
}
4 changes: 2 additions & 2 deletions src/org/joni/NativeMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

abstract class NativeMachine extends Matcher {

protected NativeMachine(Regex regex, byte[]bytes, int p, int end) {
super(regex, bytes, p, end);
protected NativeMachine(Regex regex, Region region, byte[]bytes, int p, int end) {
super(regex, region, bytes, p, end);
}
}
6 changes: 5 additions & 1 deletion src/org/joni/Regex.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ public Matcher matcher(byte[]bytes) {
}

public Matcher matcher(byte[]bytes, int p, int end) {
return factory.create(this, bytes, p, end);
return factory.create(this, numMem == 0 ? null : new Region(numMem + 1), bytes, p, end);
}

public Matcher matcherNoRegion(byte[]bytes, int p, int end) {
return factory.create(this, null, bytes, p, end);
}

public int numberOfCaptures() {
Expand Down
4 changes: 2 additions & 2 deletions src/org/joni/StackMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, Region region, byte[]bytes, int p , int end) {
super(regex, region, bytes, p, end);
stack = regex.requireStack ? fetchStack() : null;
final int n;
if (Config.USE_SUBEXP_CALL) {
Expand Down

0 comments on commit af9a0dd

Please sign in to comment.