Skip to content

Instantly share code, notes, and snippets.

@enebo
Created July 24, 2018 21:46
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/ad593950c5b5788616afd6e1ee499502 to your computer and use it in GitHub Desktop.
Save enebo/ad593950c5b5788616afd6e1ee499502 to your computer and use it in GitHub Desktop.
diff --git a/core/pom.rb b/core/pom.rb
index 61b866de2b..d0175ac334 100644
--- a/core/pom.rb
+++ b/core/pom.rb
@@ -51,7 +51,7 @@ project 'JRuby Core' do
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'
- jar 'org.jruby.joni:joni:2.1.16'
+ jar 'org.jruby.joni:joni:2.1.17-SNAPSHOT'
jar 'org.jruby.extras:bytelist:1.0.15'
jar 'org.jruby.jcodings:jcodings:1.0.30'
jar 'org.jruby:dirgra:0.3'
diff --git a/core/pom.xml b/core/pom.xml
index d31f1174f0..4a62304b72 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -172,7 +172,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.joni</groupId>
<artifactId>joni</artifactId>
- <version>2.1.16</version>
+ <version>2.1.17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jruby.extras</groupId>
diff --git a/core/src/main/java/org/jruby/RubyRegexp.java b/core/src/main/java/org/jruby/RubyRegexp.java
index 18dd800f83..a900134f84 100755
--- a/core/src/main/java/org/jruby/RubyRegexp.java
+++ b/core/src/main/java/org/jruby/RubyRegexp.java
@@ -238,6 +238,17 @@ public class RubyRegexp extends RubyObject implements ReOptions, EncodingCapable
}
}
+ public static int matcherSearch2(ThreadContext context, Matcher matcher, int start, int range, int option) {
+// try {
+// RubyThread thread = context.getThread();
+ return matcher.match(start, range, option);
+// SearchMatchTask task = new SearchMatchTask(thread, start, range, option, true);
+// return thread.executeTask(context, matcher, task);
+// } catch (InterruptedException e) {
+// throw context.runtime.newInterruptedRegexpError("Regexp Interrupted");
+// }
+ }
+
@Deprecated // not-used
public static int matcherSearch(Ruby runtime, Matcher matcher, int start, int range, int option) {
return matcherSearch(runtime.getCurrentContext(), matcher, start, range, option);
@@ -1130,14 +1141,12 @@ public class RubyRegexp extends RubyObject implements ReOptions, EncodingCapable
@JRubyMethod(name = "match?")
public IRubyObject match_p(ThreadContext context, IRubyObject str) {
- IRubyObject[] dummy = new IRubyObject[1];
- return context.runtime.newBoolean(matchPos(context, str, dummy, dummy, 0) >= 0);
+ return context.runtime.newBoolean(matchPos(context, str, 0) >= 0);
}
@JRubyMethod(name = "match?")
public IRubyObject match_p(ThreadContext context, IRubyObject str, IRubyObject pos) {
- IRubyObject[] dummy = new IRubyObject[1];
- return context.runtime.newBoolean(matchPos(context, str, dummy, dummy, RubyNumeric.num2int(pos)) >= 0);
+ return context.runtime.newBoolean(matchPos(context, str, RubyNumeric.num2int(pos)) >= 0);
}
private IRubyObject matchCommon(ThreadContext context, IRubyObject str, int pos, boolean setBackref, Block block) {
@@ -1177,6 +1186,22 @@ public class RubyRegexp extends RubyObject implements ReOptions, EncodingCapable
return search(context, str, pos, false, holder);
}
+ private int matchPos(ThreadContext context, IRubyObject arg, int pos) {
+ if (arg == context.nil) return -1;
+
+ final RubyString str = operandCheck(arg);
+ if (pos != 0) {
+ if (pos < 0) {
+ pos += str.strLength();
+ if (pos < 0) return pos;
+ }
+ if (pos > str.length()) return -1;
+ pos = str.rbStrOffset(pos);
+ }
+
+ return searchNo(context, str, pos);
+ }
+
/**
* MRI: rb_reg_search
*
@@ -1205,6 +1230,18 @@ public class RubyRegexp extends RubyObject implements ReOptions, EncodingCapable
return search(context, str, pos, reverse, holder);
}
+ final int searchNo(ThreadContext context, RubyString str, int pos) {
+ final ByteList strBL = str.getByteList();
+ final int beg = strBL.begin();
+
+ Matcher matcher = preparePattern(str).matcherNoRegions(strBL.unsafeBytes(), beg, beg + strBL.realSize());
+ try {
+ return matcherSearch2(context, matcher, beg + pos, beg, RE_OPTION_NONE);
+ } catch (JOniException je) {
+ throw context.runtime.newRegexpError(je.getMessage());
+ }
+ }
+
/**
* MRI: rb_reg_search0
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment