@@ -436,7 +436,7 @@ public abstract static class MatchInRegionTRegexNode extends PrimitiveArrayArgum
436
436
@ Child DispatchNode stringDupNode ;
437
437
@ Child TranslateInteropExceptionNode translateInteropExceptionNode ;
438
438
439
- @ Child RopeNodes .SubstringNode substringNode ;
439
+ @ Child RopeNodes .GetBytesObjectNode getBytesObjectNode ;
440
440
441
441
@ Specialization (guards = "libString.isRubyString(string)" )
442
442
protected Object matchInRegionTRegex (
@@ -466,16 +466,27 @@ protected Object matchInRegionTRegex(
466
466
}
467
467
468
468
int fromIndex = fromPos ;
469
+ final Object interopByteArray ;
470
+ final String execMethod ;
469
471
if (startPosNotZeroProfile .profile (startPos > 0 )) {
470
- rope = substring ( rope , startPos , toPos - startPos );
472
+ // GR-32765: When adopting TruffleString, use a TruffleString substring here instead
471
473
// If startPos != 0, then fromPos == startPos.
472
474
assert fromPos == startPos ;
473
475
fromIndex = 0 ;
476
+
477
+ if (getBytesObjectNode == null ) {
478
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
479
+ getBytesObjectNode = insert (RopeNodes .GetBytesObjectNode .create ());
480
+ }
481
+ interopByteArray = getBytesObjectNode .getRange (rope , startPos , toPos );
482
+ execMethod = "exec" ;
483
+ } else {
484
+ final byte [] bytes = bytesNode .execute (rope );
485
+ interopByteArray = getContext ().getEnv ().asGuestValue (bytes );
486
+ execMethod = "execBytes" ;
474
487
}
475
488
476
- final byte [] bytes = bytesNode .execute (rope );
477
- final Object interopByteArray = getContext ().getEnv ().asGuestValue (bytes );
478
- final Object result = invoke (regexInterop , tRegex , "execBytes" , interopByteArray , fromIndex );
489
+ final Object result = invoke (regexInterop , tRegex , execMethod , interopByteArray , fromIndex );
479
490
480
491
final boolean isMatch = (boolean ) readMember (resultInterop , result , "isMatch" );
481
492
@@ -570,15 +581,6 @@ private Object dupString(Object string) {
570
581
571
582
return stringDupNode .call (string , "dup" );
572
583
}
573
-
574
- private Rope substring (Rope rope , int byteOffset , int byteLength ) {
575
- if (substringNode == null ) {
576
- CompilerDirectives .transferToInterpreterAndInvalidate ();
577
- substringNode = insert (RopeNodes .SubstringNode .create ());
578
- }
579
-
580
- return substringNode .executeSubstring (rope , byteOffset , byteLength );
581
- }
582
584
}
583
585
584
586
public abstract static class MatchNode extends RubyContextNode {
0 commit comments