@@ -4504,7 +4504,7 @@ protected Object stringCharacterIndex(Rope stringRope, Rope patternRope, int off
4504
4504
}
4505
4505
4506
4506
protected boolean patternFits (Rope stringRope , Rope patternRope , int offset ) {
4507
- return patternRope .byteLength () + offset <= stringRope .byteLength ();
4507
+ return offset + patternRope .byteLength () <= stringRope .byteLength ();
4508
4508
}
4509
4509
}
4510
4510
@@ -4526,16 +4526,11 @@ protected RubyNode coercePatternToRope(RubyNode pattern) {
4526
4526
return ToRopeNodeGen .create (pattern );
4527
4527
}
4528
4528
4529
- @ Specialization (guards = "offset < 0" )
4530
- protected Object stringByteIndexNegativeOffset (Rope stringRope , Rope patternRope , int offset ) {
4531
- return nil ;
4532
- }
4533
-
4534
4529
@ Specialization (
4535
4530
guards = {
4536
4531
"offset >= 0" ,
4537
4532
"singleByteOptimizableNode.execute(stringRope)" ,
4538
- "patternRope.byteLength() > stringRope.byteLength( )" })
4533
+ "!patternFits(stringRope, patternRope, offset )" })
4539
4534
protected Object stringByteIndexPatternTooLarge (Rope stringRope , Rope patternRope , int offset ) {
4540
4535
return nil ;
4541
4536
}
@@ -4544,7 +4539,7 @@ protected Object stringByteIndexPatternTooLarge(Rope stringRope, Rope patternRop
4544
4539
guards = {
4545
4540
"offset >= 0" ,
4546
4541
"singleByteOptimizableNode.execute(stringRope)" ,
4547
- "patternRope.byteLength() <= stringRope.byteLength( )" })
4542
+ "patternFits(stringRope, patternRope, offset )" })
4548
4543
protected Object stringByteIndexSingleByteOptimizable (Rope stringRope , Rope patternRope , int offset ,
4549
4544
@ Cached RopeNodes .BytesNode stringBytesNode ,
4550
4545
@ Cached RopeNodes .BytesNode patternBytesNode ,
@@ -4577,7 +4572,7 @@ protected Object stringByteIndexSingleByteOptimizable(Rope stringRope, Rope patt
4577
4572
guards = {
4578
4573
"offset >= 0" ,
4579
4574
"!singleByteOptimizableNode.execute(stringRope)" ,
4580
- "patternRope.byteLength() <= stringRope.byteLength( )" })
4575
+ "patternFits(stringRope, patternRope, offset )" })
4581
4576
protected Object stringByteIndex (Rope stringRope , Rope patternRope , int offset ,
4582
4577
@ Cached RopeNodes .CalculateCharacterLengthNode calculateCharacterLengthNode ,
4583
4578
@ Cached RopeNodes .BytesNode stringBytesNode ,
@@ -4607,6 +4602,10 @@ protected Object stringByteIndex(Rope stringRope, Rope patternRope, int offset,
4607
4602
4608
4603
return nil ;
4609
4604
}
4605
+
4606
+ protected boolean patternFits (Rope stringRope , Rope patternRope , int offset ) {
4607
+ return offset + patternRope .byteLength () <= stringRope .byteLength ();
4608
+ }
4610
4609
}
4611
4610
4612
4611
/** Calculates the byte offset of a character, indicated by a character index, starting from a provided byte offset
0 commit comments