29
29
import com .oracle .truffle .api .dsl .*;
30
30
import com .oracle .truffle .api .frame .VirtualFrame ;
31
31
import com .oracle .truffle .api .nodes .Node ;
32
+ import com .oracle .truffle .api .object .DynamicObject ;
32
33
import com .oracle .truffle .api .object .DynamicObjectFactory ;
33
34
import com .oracle .truffle .api .object .Shape ;
34
35
import com .oracle .truffle .api .source .SourceSection ;
42
43
import org .joni .Matcher ;
43
44
import org .joni .Option ;
44
45
import org .jruby .Ruby ;
46
+ import org .jruby .runtime .Helpers ;
45
47
import org .jruby .truffle .nodes .RubyNode ;
46
48
import org .jruby .truffle .nodes .cast .CmpIntNode ;
47
49
import org .jruby .truffle .nodes .cast .CmpIntNodeGen ;
@@ -97,19 +99,19 @@ public static void set(RubyString string, ByteList bytes) {
97
99
public static void forceEncoding (RubyString string , Encoding encoding ) {
98
100
string .modify ();
99
101
string .clearCodeRange ();
100
- StringSupport .associateEncoding (string , encoding );
102
+ StringSupport .associateEncoding (string . getCodeRangeable () , encoding );
101
103
string .clearCodeRange ();
102
104
}
103
105
104
106
public static int length (RubyString string ) {
105
107
if (CompilerDirectives .injectBranchProbability (
106
108
CompilerDirectives .FASTPATH_PROBABILITY ,
107
- StringSupport .isSingleByteOptimizable (string , string .getByteList ().getEncoding ()))) {
109
+ StringSupport .isSingleByteOptimizable (string . getCodeRangeable () , string .getByteList ().getEncoding ()))) {
108
110
109
111
return string .getByteList ().getRealSize ();
110
112
111
113
} else {
112
- return StringSupport .strLengthFromRubyString (string );
114
+ return StringSupport .strLengthFromRubyString (string . getCodeRangeable () );
113
115
}
114
116
}
115
117
@@ -127,7 +129,7 @@ public static int clampExclusiveIndex(RubyString string, int index) {
127
129
128
130
@ TruffleBoundary
129
131
public static Encoding checkEncoding (RubyString string , CodeRangeable other , Node node ) {
130
- final Encoding encoding = StringSupport .areCompatible (string , other );
132
+ final Encoding encoding = StringSupport .areCompatible (string . getCodeRangeable () , other );
131
133
132
134
if (encoding == null ) {
133
135
throw new RaiseException (
@@ -142,7 +144,7 @@ public static Encoding checkEncoding(RubyString string, CodeRangeable other, Nod
142
144
}
143
145
144
146
public static boolean singleByteOptimizable (RubyString string ) {
145
- return StringSupport .isSingleByteOptimizable (string , EncodingUtils .STR_ENC_GET (string ));
147
+ return StringSupport .isSingleByteOptimizable (string . getCodeRangeable () , EncodingUtils .STR_ENC_GET (string . getCodeRangeable () ));
146
148
}
147
149
148
150
public static RubyString createEmptyString (RubyClass stringClass ) {
@@ -188,7 +190,7 @@ public AddNode(RubyContext context, SourceSection sourceSection) {
188
190
189
191
@ Specialization
190
192
public RubyString add (RubyString string , RubyString other ) {
191
- final Encoding enc = checkEncoding (string , other , this );
193
+ final Encoding enc = checkEncoding (string , other . getCodeRangeable () , this );
192
194
final RubyString ret = createString (StringSupport .addByteLists (string .getByteList (), other .getByteList ()));
193
195
194
196
if (taintResultNode == null ) {
@@ -311,7 +313,7 @@ public int compare(RubyString a, RubyString b) {
311
313
312
314
final int ret = a .getByteList ().cmp (b .getByteList ());
313
315
314
- if ((ret == 0 ) && !StringSupport .areComparable (a , b )) {
316
+ if ((ret == 0 ) && !StringSupport .areComparable (a . getCodeRangeable () , b . getCodeRangeable () )) {
315
317
return a .getByteList ().getEncoding ().getIndex () > b .getByteList ().getEncoding ().getIndex () ? 1 : -1 ;
316
318
}
317
319
@@ -427,7 +429,7 @@ public RubyString concat(RubyString string, RubyString other) {
427
429
final int [] ptr_cr_ret = { codeRange };
428
430
429
431
try {
430
- EncodingUtils .encCrStrBufCat (getContext ().getRuntime (), string , other .getByteList (), other .getByteList ().getEncoding (), codeRange , ptr_cr_ret );
432
+ EncodingUtils .encCrStrBufCat (getContext ().getRuntime (), string . getCodeRangeable () , other .getByteList (), other .getByteList ().getEncoding (), codeRange , ptr_cr_ret );
431
433
} catch (org .jruby .exceptions .RaiseException e ) {
432
434
if (e .getException ().getMetaClass () == getContext ().getRuntime ().getEncodingCompatibilityError ()) {
433
435
CompilerDirectives .transferToInterpreter ();
@@ -753,7 +755,7 @@ public CaseCmpNode(RubyContext context, SourceSection sourceSection) {
753
755
public Object caseCmpSingleByte (RubyString string , RubyString other ) {
754
756
// Taken from org.jruby.RubyString#casecmp19.
755
757
756
- if (StringSupport .areCompatible (string , other ) == null ) {
758
+ if (StringSupport .areCompatible (string . getCodeRangeable () , other . getCodeRangeable () ) == null ) {
757
759
return nil ();
758
760
}
759
761
@@ -764,7 +766,7 @@ public Object caseCmpSingleByte(RubyString string, RubyString other) {
764
766
public Object caseCmp (RubyString string , RubyString other ) {
765
767
// Taken from org.jruby.RubyString#casecmp19 and
766
768
767
- final Encoding encoding = StringSupport .areCompatible (string , other );
769
+ final Encoding encoding = StringSupport .areCompatible (string . getCodeRangeable () , other . getCodeRangeable () );
768
770
769
771
if (encoding == null ) {
770
772
return nil ();
@@ -779,8 +781,8 @@ private int multiByteCasecmp(Encoding enc, ByteList value, ByteList otherValue)
779
781
}
780
782
781
783
public static boolean bothSingleByteOptimizable (RubyString string , RubyString other ) {
782
- final boolean stringSingleByteOptimizable = StringSupport .isSingleByteOptimizable (string , string .getByteList ().getEncoding ());
783
- final boolean otherSingleByteOptimizable = StringSupport .isSingleByteOptimizable (other , other .getByteList ().getEncoding ());
784
+ final boolean stringSingleByteOptimizable = StringSupport .isSingleByteOptimizable (string . getCodeRangeable () , string .getByteList ().getEncoding ());
785
+ final boolean otherSingleByteOptimizable = StringSupport .isSingleByteOptimizable (other . getCodeRangeable () , other .getByteList ().getEncoding ());
784
786
785
787
return stringSingleByteOptimizable && otherSingleByteOptimizable ;
786
788
}
@@ -815,7 +817,7 @@ public Object chopBang(VirtualFrame frame, RubyString string) {
815
817
816
818
@ TruffleBoundary
817
819
private int choppedLength (RubyString string ) {
818
- return StringSupport .choppedLength19 (string , getContext ().getRuntime ());
820
+ return StringSupport .choppedLength19 (string . getCodeRangeable () , getContext ().getRuntime ());
819
821
}
820
822
}
821
823
@@ -859,7 +861,7 @@ private int countSlow(RubyString string, RubyString[] otherStrings) {
859
861
for (int i = 1 ; i < otherStrings .length ; i ++) {
860
862
otherStr = otherStrings [i ];
861
863
862
- enc = checkEncoding (string , otherStr , this );
864
+ enc = checkEncoding (string , otherStr . getCodeRangeable () , this );
863
865
tables = StringSupport .trSetupTable (otherStr .getByteList (), getContext ().getRuntime (), table , tables , false , enc );
864
866
}
865
867
@@ -893,7 +895,7 @@ public Object crypt(RubyString string, RubyString salt) {
893
895
final RubyString otherStr = StringNodes .createString (getContext ().getCoreLibrary ().getStringClass (), otherBL );
894
896
895
897
otherStr .modify ();
896
- StringSupport .associateEncoding (otherStr , ascii8bit );
898
+ StringSupport .associateEncoding (otherStr . getCodeRangeable () , ascii8bit );
897
899
898
900
if (otherBL .length () < 2 ) {
899
901
CompilerDirectives .transferToInterpreter ();
@@ -919,7 +921,7 @@ public Object crypt(RubyString string, RubyString salt) {
919
921
}
920
922
921
923
final RubyString result = StringNodes .createString (getContext ().getCoreLibrary ().getStringClass (), new ByteList (cryptedString , 0 , cryptedString .length - 1 ));
922
- StringSupport .associateEncoding (result , ascii8bit );
924
+ StringSupport .associateEncoding (result . getCodeRangeable () , ascii8bit );
923
925
924
926
return result ;
925
927
}
@@ -973,19 +975,19 @@ public Object deleteBang(VirtualFrame frame, RubyString string, Object... args)
973
975
@ TruffleBoundary
974
976
private Object deleteBangSlow (RubyString string , RubyString ... otherStrings ) {
975
977
RubyString otherString = otherStrings [0 ];
976
- Encoding enc = checkEncoding (string , otherString , this );
978
+ Encoding enc = checkEncoding (string , otherString . getCodeRangeable () , this );
977
979
978
980
boolean [] squeeze = new boolean [StringSupport .TRANS_SIZE + 1 ];
979
981
StringSupport .TrTables tables = StringSupport .trSetupTable (otherString .getByteList (),
980
982
getContext ().getRuntime (),
981
983
squeeze , null , true , enc );
982
984
983
985
for (int i = 1 ; i < otherStrings .length ; i ++) {
984
- enc = checkEncoding (string , otherStrings [i ], this );
986
+ enc = checkEncoding (string , otherStrings [i ]. getCodeRangeable () , this );
985
987
tables = StringSupport .trSetupTable (otherStrings [i ].getByteList (), getContext ().getRuntime (), squeeze , tables , false , enc );
986
988
}
987
989
988
- if (StringSupport .delete_bangCommon19 (string , getContext ().getRuntime (), squeeze , tables , enc ) == null ) {
990
+ if (StringSupport .delete_bangCommon19 (string . getCodeRangeable () , getContext ().getRuntime (), squeeze , tables , enc ) == null ) {
989
991
return nil ();
990
992
}
991
993
@@ -1396,7 +1398,7 @@ public Object lstripBang(RubyString string) {
1396
1398
return nil ();
1397
1399
}
1398
1400
1399
- final Encoding enc = EncodingUtils .STR_ENC_GET (string );
1401
+ final Encoding enc = EncodingUtils .STR_ENC_GET (string . getCodeRangeable () );
1400
1402
final int s = string .getByteList ().getBegin ();
1401
1403
final int end = s + string .getByteList ().getRealSize ();
1402
1404
final byte []bytes = string .getByteList ().getUnsafeBytes ();
@@ -1557,7 +1559,7 @@ public Object rstripBang(RubyString string) {
1557
1559
return nil ();
1558
1560
}
1559
1561
1560
- final Encoding enc = EncodingUtils .STR_ENC_GET (string );
1562
+ final Encoding enc = EncodingUtils .STR_ENC_GET (string . getCodeRangeable () );
1561
1563
final byte [] bytes = string .getByteList ().getUnsafeBytes ();
1562
1564
final int start = string .getByteList ().getBegin ();
1563
1565
final int end = start + string .getByteList ().getRealSize ();
@@ -1621,7 +1623,7 @@ public RubyBasicObject swapcaseSingleByte(RubyString string) {
1621
1623
final int end = s + value .getRealSize ();
1622
1624
final byte []bytes = value .getUnsafeBytes ();
1623
1625
1624
- if (singleByteOptimizableProfile .profile (StringSupport .isSingleByteOptimizable (string , enc ))) {
1626
+ if (singleByteOptimizableProfile .profile (StringSupport .isSingleByteOptimizable (string . getCodeRangeable () , enc ))) {
1625
1627
if (StringSupport .singleByteSwapcase (bytes , s , end )) {
1626
1628
return string ;
1627
1629
}
@@ -1835,7 +1837,7 @@ public int sizeSingleByte(RubyString string) {
1835
1837
1836
1838
@ Specialization (guards = "!isSingleByteOptimizable(string)" )
1837
1839
public int size (RubyString string ) {
1838
- return StringSupport .strLengthFromRubyString (string );
1840
+ return StringSupport .strLengthFromRubyString (string . getCodeRangeable () );
1839
1841
}
1840
1842
}
1841
1843
@@ -1896,15 +1898,15 @@ public Object squeezeBang(VirtualFrame frame, RubyString string, Object... args)
1896
1898
}
1897
1899
1898
1900
RubyString otherStr = otherStrings [0 ];
1899
- Encoding enc = checkEncoding (string , otherStr , this );
1901
+ Encoding enc = checkEncoding (string , otherStr . getCodeRangeable () , this );
1900
1902
final boolean squeeze [] = new boolean [StringSupport .TRANS_SIZE + 1 ];
1901
1903
StringSupport .TrTables tables = StringSupport .trSetupTable (otherStr .getByteList (), getContext ().getRuntime (), squeeze , null , true , enc );
1902
1904
1903
1905
boolean singlebyte = singleByteOptimizable (string ) && singleByteOptimizable (otherStr );
1904
1906
1905
1907
for (int i = 1 ; i < otherStrings .length ; i ++) {
1906
1908
otherStr = otherStrings [i ];
1907
- enc = string .checkEncoding (otherStr );
1909
+ enc = string .checkEncoding (otherStr . getCodeRangeable () );
1908
1910
singlebyte = singlebyte && singleByteOptimizable (otherStr );
1909
1911
tables = StringSupport .trSetupTable (otherStr .getByteList (), getContext ().getRuntime (), squeeze , tables , false , enc );
1910
1912
}
@@ -2470,18 +2472,18 @@ public static int checkIndexForRef(RubyString string, int index, RubyNode node)
2470
2472
2471
2473
@ TruffleBoundary
2472
2474
public static void replaceInternal (RubyString string , int start , int length , RubyString replacement ) {
2473
- StringSupport .replaceInternal19 (start , length , string , replacement );
2475
+ StringSupport .replaceInternal19 (start , length , string . getCodeRangeable () , replacement . getCodeRangeable () );
2474
2476
}
2475
2477
2476
2478
@ TruffleBoundary
2477
2479
private static Object trTransHelper (RubyContext context , RubyString self , RubyString fromStr , RubyString toStr , boolean sFlag ) {
2478
- final CodeRangeable ret = StringSupport .trTransHelper (context .getRuntime (), self , fromStr , toStr , sFlag );
2480
+ final CodeRangeable ret = StringSupport .trTransHelper (context .getRuntime (), self . getCodeRangeable () , fromStr . getCodeRangeable () , toStr . getCodeRangeable () , sFlag );
2479
2481
2480
2482
if (ret == null ) {
2481
2483
return context .getCoreLibrary ().getNilObject ();
2482
2484
}
2483
2485
2484
- return ret ;
2486
+ return self ;
2485
2487
}
2486
2488
}
2487
2489
0 commit comments