75
75
import java .io .UnsupportedEncodingException ;
76
76
import java .nio .charset .StandardCharsets ;
77
77
78
+ import com .oracle .truffle .api .dsl .Bind ;
78
79
import org .jcodings .Config ;
79
80
import org .jcodings .Encoding ;
80
81
import org .jcodings .exception .EncodingException ;
@@ -4677,24 +4678,25 @@ protected Object stringRindexEmptyPattern(Object string, Object pattern, int byt
4677
4678
}
4678
4679
4679
4680
@ Specialization (guards = {
4680
- "isSingleByteString(libPattern.getRope(pattern) )" ,
4681
- "!isBrokenCodeRange(libPattern.getRope(pattern) , codeRangeNode)" ,
4682
- "canMemcmp(libString.getRope(string), libPattern.getRope(pattern) , singleByteNode)" })
4681
+ "isSingleByteString(patternRope )" ,
4682
+ "!isBrokenCodeRange(patternRope , codeRangeNode)" ,
4683
+ "canMemcmp(libString.getRope(string), patternRope , singleByteNode)" })
4683
4684
protected Object stringRindexSingleBytePattern (Object string , Object pattern , int byteOffset ,
4685
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libPattern ,
4686
+ @ Bind ("libPattern.getRope(pattern)" ) Rope patternRope ,
4684
4687
@ Cached RopeNodes .BytesNode bytesNode ,
4685
4688
@ Cached BranchProfile startTooLargeProfile ,
4686
4689
@ Cached BranchProfile matchFoundProfile ,
4687
4690
@ Cached BranchProfile noMatchProfile ,
4688
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libString ,
4689
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libPattern ) {
4691
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libString ) {
4690
4692
assert byteOffset >= 0 ;
4691
4693
4692
4694
checkEncoding (string , pattern );
4693
4695
4694
4696
final Rope sourceRope = libString .getRope (string );
4695
4697
final int end = sourceRope .byteLength ();
4696
4698
final byte [] sourceBytes = bytesNode .execute (sourceRope );
4697
- final byte searchByte = bytesNode .execute (libPattern . getRope ( pattern ) )[0 ];
4699
+ final byte searchByte = bytesNode .execute (patternRope )[0 ];
4698
4700
int normalizedStart = byteOffset ;
4699
4701
4700
4702
if (normalizedStart >= end ) {
@@ -4714,26 +4716,27 @@ protected Object stringRindexSingleBytePattern(Object string, Object pattern, in
4714
4716
}
4715
4717
4716
4718
@ Specialization (guards = {
4717
- "!isEmpty(libPattern.getRope(pattern) )" ,
4718
- "!isSingleByteString(libPattern.getRope(pattern) )" ,
4719
- "!isBrokenCodeRange(libPattern.getRope(pattern) , codeRangeNode)" ,
4720
- "canMemcmp(libString.getRope(string), libPattern.getRope(pattern) , singleByteNode)" })
4719
+ "!isEmpty(patternRope )" ,
4720
+ "!isSingleByteString(patternRope )" ,
4721
+ "!isBrokenCodeRange(patternRope , codeRangeNode)" ,
4722
+ "canMemcmp(libString.getRope(string), patternRope , singleByteNode)" })
4721
4723
protected Object stringRindexMultiBytePattern (Object string , Object pattern , int byteOffset ,
4724
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libPattern ,
4725
+ @ Bind ("libPattern.getRope(pattern)" ) Rope patternRope ,
4722
4726
@ Cached RopeNodes .BytesNode bytesNode ,
4723
4727
@ Cached BranchProfile startOutOfBoundsProfile ,
4724
4728
@ Cached BranchProfile startTooCloseToEndProfile ,
4725
4729
@ Cached BranchProfile matchFoundProfile ,
4726
4730
@ Cached BranchProfile noMatchProfile ,
4727
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libString ,
4728
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libPattern ) {
4731
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libString ) {
4729
4732
assert byteOffset >= 0 ;
4730
4733
4731
4734
checkEncoding (string , pattern );
4732
4735
4733
4736
final Rope sourceRope = libString .getRope (string );
4734
4737
final int end = sourceRope .byteLength ();
4735
4738
final byte [] sourceBytes = bytesNode .execute (sourceRope );
4736
- final Rope searchRope = libPattern . getRope ( pattern ) ;
4739
+ final Rope searchRope = patternRope ;
4737
4740
final int matchSize = searchRope .byteLength ();
4738
4741
final byte [] searchBytes = bytesNode .execute (searchRope );
4739
4742
int normalizedStart = byteOffset ;
@@ -4769,22 +4772,22 @@ protected Object stringRindexBrokenPattern(Object string, Object pattern, int by
4769
4772
}
4770
4773
4771
4774
@ Specialization (guards = {
4772
- "!isBrokenCodeRange(libPattern.getRope(pattern) , codeRangeNode)" ,
4773
- "!canMemcmp(libString.getRope(string), libPattern.getRope(pattern) , singleByteNode)" })
4775
+ "!isBrokenCodeRange(patternRope , codeRangeNode)" ,
4776
+ "!canMemcmp(libString.getRope(string), patternRope , singleByteNode)" })
4774
4777
protected Object stringRindex (Object string , Object pattern , int byteOffset ,
4778
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libPattern ,
4779
+ @ Bind ("libPattern.getRope(pattern)" ) Rope patternRope ,
4775
4780
@ Cached RopeNodes .BytesNode stringBytes ,
4776
4781
@ Cached RopeNodes .BytesNode patternBytes ,
4777
4782
@ Cached RopeNodes .GetByteNode patternGetByteNode ,
4778
4783
@ Cached RopeNodes .GetByteNode stringGetByteNode ,
4779
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libString ,
4780
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libPattern ) {
4784
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libString ) {
4781
4785
// Taken from Rubinius's String::rindex.
4782
4786
assert byteOffset >= 0 ;
4783
4787
4784
4788
int pos = byteOffset ;
4785
4789
4786
4790
final Rope stringRope = libString .getRope (string );
4787
- final Rope patternRope = libPattern .getRope (pattern );
4788
4791
final int total = stringRope .byteLength ();
4789
4792
final int matchSize = patternRope .byteLength ();
4790
4793
0 commit comments