|
30 | 30 | import com.oracle.truffle.api.dsl.GenerateInline;
|
31 | 31 | import com.oracle.truffle.api.dsl.ImportStatic;
|
32 | 32 | import com.oracle.truffle.api.dsl.NeverDefault;
|
33 |
| -import com.oracle.truffle.api.interop.InteropException; |
34 | 33 | import com.oracle.truffle.api.interop.InteropLibrary;
|
35 | 34 | import com.oracle.truffle.api.library.CachedLibrary;
|
36 | 35 | import com.oracle.truffle.api.profiles.InlinedBranchProfile;
|
|
68 | 67 | import org.truffleruby.core.string.StringNodes.StringAppendPrimitiveNode;
|
69 | 68 | import org.truffleruby.core.string.StringOperations;
|
70 | 69 | import org.truffleruby.core.string.StringUtils;
|
| 70 | +import org.truffleruby.interop.InteropNodes; |
71 | 71 | import org.truffleruby.interop.TranslateInteropExceptionNode;
|
72 | 72 | import org.truffleruby.language.LazyWarnNode;
|
73 | 73 | import org.truffleruby.language.RubyBaseNode;
|
@@ -965,16 +965,18 @@ static Object matchInRegionTRegex(
|
965 | 965 | tstringToMatch = tstring;
|
966 | 966 | execMethod = "execBoolean";
|
967 | 967 | }
|
968 |
| - final Object result = invoke(node, regexInterop, tRegex, execMethod, translateInteropExceptionNode, |
969 |
| - tstringToMatch, fromIndex); |
| 968 | + |
| 969 | + final Object[] arguments = new Object[]{ tstringToMatch, fromIndex }; |
| 970 | + final Object result = InteropNodes.invokeMember(node, regexInterop, tRegex, execMethod, arguments, |
| 971 | + translateInteropExceptionNode); |
970 | 972 |
|
971 | 973 | if (createMatchDataProfile.profile(node, createMatchData)) {
|
972 |
| - final boolean isMatch = (boolean) readMember(node, resultInterop, result, "isMatch", |
| 974 | + final boolean isMatch = (boolean) InteropNodes.readMember(node, resultInterop, result, "isMatch", |
973 | 975 | translateInteropExceptionNode);
|
974 | 976 |
|
975 | 977 | if (matchFoundProfile.profile(node, isMatch)) {
|
976 | 978 | final int groupCount = groupCountProfile
|
977 |
| - .profile(node, (int) readMember(node, regexInterop, tRegex, "groupCount", |
| 979 | + .profile(node, (int) InteropNodes.readMember(node, regexInterop, tRegex, "groupCount", |
978 | 980 | translateInteropExceptionNode));
|
979 | 981 | final Region region = new Region(groupCount);
|
980 | 982 |
|
@@ -1033,26 +1035,30 @@ private static Object createMatchData(Node node, RubyRegexp regexp, Object strin
|
1033 | 1035 | return matchData;
|
1034 | 1036 | }
|
1035 | 1037 |
|
1036 |
| - private static Object readMember(Node node, InteropLibrary interop, Object receiver, String name, |
1037 |
| - TranslateInteropExceptionNode translateInteropExceptionNode) { |
1038 |
| - try { |
1039 |
| - return interop.readMember(receiver, name); |
1040 |
| - } catch (InteropException e) { |
1041 |
| - throw translateInteropExceptionNode.execute(node, e); |
1042 |
| - } |
| 1038 | + private static Object dupString(Object string, DispatchNode stringDupNode) { |
| 1039 | + return stringDupNode.call(string, "dup"); |
1043 | 1040 | }
|
| 1041 | + } |
1044 | 1042 |
|
1045 |
| - private static Object invoke(Node node, InteropLibrary interop, Object receiver, String member, |
1046 |
| - TranslateInteropExceptionNode translateInteropExceptionNode, Object... args) { |
1047 |
| - try { |
1048 |
| - return interop.invokeMember(receiver, member, args); |
1049 |
| - } catch (InteropException e) { |
1050 |
| - throw translateInteropExceptionNode.executeInInvokeMember(node, e, receiver, args); |
| 1043 | + @CoreMethod(names = "linear_time?", onSingleton = true, required = 1) |
| 1044 | + public abstract static class IsLinearTimeNode extends CoreMethodArrayArgumentsNode { |
| 1045 | + |
| 1046 | + @Specialization |
| 1047 | + Object isLinearTime(RubyRegexp regexp, |
| 1048 | + @Cached InlinedConditionProfile tRegexCouldNotCompileProfile, |
| 1049 | + @Cached TRegexCompileNode tRegexCompileNode, |
| 1050 | + @CachedLibrary(limit = "getInteropCacheLimit()") InteropLibrary regexInterop, |
| 1051 | + @Cached TranslateInteropExceptionNode translateInteropExceptionNode, |
| 1052 | + @Bind("this") Node node) { |
| 1053 | + final Object compiledRegex = tRegexCompileNode.executeTRegexCompile(regexp, false, regexp.encoding); |
| 1054 | + |
| 1055 | + if (tRegexCouldNotCompileProfile.profile(node, compiledRegex == nil)) { |
| 1056 | + return nil; |
1051 | 1057 | }
|
1052 |
| - } |
1053 | 1058 |
|
1054 |
| - private static Object dupString(Object string, DispatchNode stringDupNode) { |
1055 |
| - return stringDupNode.call(string, "dup"); |
| 1059 | + boolean isBacktracking = (boolean) InteropNodes.readMember(node, regexInterop, compiledRegex, |
| 1060 | + "isBacktracking", translateInteropExceptionNode); |
| 1061 | + return !isBacktracking; |
1056 | 1062 | }
|
1057 | 1063 | }
|
1058 | 1064 |
|
|
0 commit comments