|
75 | 75 | @CoreModule("Truffle::RegexpOperations")
|
76 | 76 | public class TruffleRegexpNodes {
|
77 | 77 |
|
78 |
| - public static Matcher createMatcher(RubyContext context, RubyRegexp regexp, Rope stringRope, byte[] stringBytes, |
79 |
| - boolean encodingConversion, int start, Node currentNode) { |
80 |
| - final Encoding enc = checkEncoding(regexp, stringRope.getEncoding(), stringRope.getCodeRange()); |
81 |
| - Regex regex = regexp.regex; |
82 |
| - |
83 |
| - if (encodingConversion && regex.getEncoding() != enc) { |
84 |
| - EncodingCache encodingCache = regexp.cachedEncodings; |
85 |
| - regex = encodingCache.getOrCreate(enc, e -> makeRegexpForEncoding(context, regexp, e, currentNode)); |
86 |
| - } |
87 |
| - |
88 |
| - return getMatcher(regex, stringBytes, start); |
89 |
| - } |
90 |
| - |
91 | 78 | public static Encoding checkEncoding(RubyRegexp regexp, Encoding strEnc, CodeRange codeRange) {
|
92 | 79 | final Encoding regexEnc = regexp.regex.getEncoding();
|
93 | 80 |
|
@@ -397,14 +384,15 @@ protected Object matchInRegion(
|
397 | 384 | @Cached TruffleRegexpNodes.MatchNode matchNode,
|
398 | 385 | @CachedLibrary(limit = "2") RubyStringLibrary libString) {
|
399 | 386 | Rope rope = libString.getRope(string);
|
400 |
| - Matcher matcher = createMatcher( |
401 |
| - getContext(), |
402 |
| - regexp, |
403 |
| - rope, |
404 |
| - bytesNode.execute(rope), |
405 |
| - encodingConversion, |
406 |
| - startPos, |
407 |
| - this); |
| 387 | + final Encoding enc = checkEncoding(regexp, rope.getEncoding(), rope.getCodeRange()); |
| 388 | + Regex regex = regexp.regex; |
| 389 | + |
| 390 | + if (regex.getEncoding() != enc) { |
| 391 | + EncodingCache encodingCache = regexp.cachedEncodings; |
| 392 | + regex = encodingCache.getOrCreate(enc, e -> makeRegexpForEncoding(getContext(), regexp, e, this)); |
| 393 | + } |
| 394 | + |
| 395 | + Matcher matcher = getMatcher(regex, bytesNode.execute(rope), startPos); |
408 | 396 | return matchNode.execute(regexp, string, matcher, fromPos, toPos, atStart);
|
409 | 397 | }
|
410 | 398 | }
|
|
0 commit comments