28
28
import org .jcodings .specific .ASCIIEncoding ;
29
29
import org .jcodings .specific .USASCIIEncoding ;
30
30
import org .jcodings .specific .UTF8Encoding ;
31
+ import org .truffleruby .core .encoding .EncodingNodes ;
31
32
import org .truffleruby .core .rope .RopeNodesFactory .SetByteNodeGen ;
32
33
import org .truffleruby .core .string .StringAttributes ;
33
34
import org .truffleruby .core .string .StringSupport ;
@@ -1185,21 +1186,23 @@ public int getCodePointUTF8(Rope rope, int index,
1185
1186
@ Cached ("create()" ) GetByteNode getByteNode ,
1186
1187
@ Cached ("create()" ) BytesNode bytesNode ,
1187
1188
@ Cached ("create()" ) CodeRangeNode codeRangeNode ,
1189
+ @ Cached ("create()" ) EncodingNodes .GetActualEncodingNode getActualEncodingNode ,
1188
1190
@ Cached ("createBinaryProfile()" ) ConditionProfile singleByteCharProfile ,
1189
1191
@ Cached ("create()" ) BranchProfile errorProfile ) {
1190
1192
final int firstByte = getByteNode .executeGetByte (rope , index );
1191
1193
if (singleByteCharProfile .profile (firstByte < 128 )) {
1192
1194
return firstByte ;
1193
1195
}
1194
1196
1195
- return getCodePointMultiByte (rope , index , errorProfile , bytesNode , codeRangeNode );
1197
+ return getCodePointMultiByte (rope , index , errorProfile , bytesNode , codeRangeNode , getActualEncodingNode );
1196
1198
}
1197
1199
1198
1200
@ Specialization (guards = { "!singleByteOptimizableNode.execute(rope)" , "!rope.getEncoding().isUTF8()" })
1199
1201
public int getCodePointMultiByte (Rope rope , int index ,
1200
1202
@ Cached ("create()" ) BranchProfile errorProfile ,
1201
1203
@ Cached ("create()" ) BytesNode bytesNode ,
1202
- @ Cached ("create()" ) CodeRangeNode codeRangeNode ) {
1204
+ @ Cached ("create()" ) CodeRangeNode codeRangeNode ,
1205
+ @ Cached ("create()" ) EncodingNodes .GetActualEncodingNode getActualEncodingNode ) {
1203
1206
final byte [] bytes = bytesNode .execute (rope );
1204
1207
final Encoding encoding = rope .getEncoding ();
1205
1208
final CodeRange codeRange = codeRangeNode .execute (rope );
@@ -1210,7 +1213,9 @@ public int getCodePointMultiByte(Rope rope, int index,
1210
1213
throw new RaiseException (getContext (), getContext ().getCoreExceptions ().argumentError ("invalid byte sequence in " + encoding , null ));
1211
1214
}
1212
1215
1213
- return mbcToCode (encoding , bytes , index , rope .byteLength ());
1216
+ final Encoding actualEncoding = getActualEncodingNode .execute (rope );
1217
+
1218
+ return mbcToCode (actualEncoding , bytes , index , rope .byteLength ());
1214
1219
}
1215
1220
1216
1221
@ TruffleBoundary
0 commit comments