@@ -4416,16 +4416,11 @@ protected RubyNode coercePatternToRope(RubyNode pattern) {
4416
4416
return ToRopeNodeGen .create (pattern );
4417
4417
}
4418
4418
4419
- @ Specialization (guards = "offset < 0" )
4420
- protected Object stringCharacterIndexNegativeOffset (Rope stringRope , Rope patternRope , int offset ) {
4421
- return nil ;
4422
- }
4423
-
4424
4419
@ Specialization (
4425
4420
guards = {
4426
4421
"offset >= 0" ,
4427
4422
"singleByteOptimizableNode.execute(stringRope)" ,
4428
- "patternRope.byteLength() > stringRope.byteLength( )" })
4423
+ "!patternFits(stringRope, patternRope, offset )" })
4429
4424
protected Object stringCharacterIndexPatternTooLarge (Rope stringRope , Rope patternRope , int offset ) {
4430
4425
return nil ;
4431
4426
}
@@ -4434,7 +4429,7 @@ protected Object stringCharacterIndexPatternTooLarge(Rope stringRope, Rope patte
4434
4429
guards = {
4435
4430
"offset >= 0" ,
4436
4431
"singleByteOptimizableNode.execute(stringRope)" ,
4437
- "patternRope.byteLength() <= stringRope.byteLength( )" })
4432
+ "patternFits(stringRope, patternRope, offset )" })
4438
4433
protected Object stringCharacterIndexSingleByteOptimizable (Rope stringRope , Rope patternRope , int offset ,
4439
4434
@ Cached RopeNodes .BytesNode stringBytesNode ,
4440
4435
@ Cached RopeNodes .BytesNode patternBytesNode ,
@@ -4507,6 +4502,10 @@ protected Object stringCharacterIndex(Rope stringRope, Rope patternRope, int off
4507
4502
4508
4503
return nil ;
4509
4504
}
4505
+
4506
+ protected boolean patternFits (Rope stringRope , Rope patternRope , int offset ) {
4507
+ return patternRope .byteLength () + offset <= stringRope .byteLength ();
4508
+ }
4510
4509
}
4511
4510
4512
4511
@ Primitive (name = "string_byte_index" , lowerFixnum = 2 )
0 commit comments