File tree Expand file tree Collapse file tree 2 files changed +20
-17
lines changed
java/org/truffleruby/core/encoding Expand file tree Collapse file tree 2 files changed +20
-17
lines changed Original file line number Diff line number Diff line change @@ -474,6 +474,21 @@ public boolean isUnicode(DynamicObject encoding) {
474
474
475
475
}
476
476
477
+ @ Primitive (name = "get_actual_encoding" , needsSelf = false )
478
+ public abstract static class GetActualEncodingPrimitiveNode extends PrimitiveArrayArgumentsNode {
479
+
480
+ @ Specialization
481
+ public DynamicObject getActualEncoding (DynamicObject string ,
482
+ @ Cached ("create()" ) GetActualEncodingNode getActualEncodingNode ,
483
+ @ Cached ("create()" ) GetRubyEncodingNode getRubyEncodingNode ) {
484
+ final Rope rope = StringOperations .rope (string );
485
+ final Encoding actualEncoding = getActualEncodingNode .execute (rope );
486
+
487
+ return getRubyEncodingNode .executeGetRubyEncoding (actualEncoding );
488
+ }
489
+
490
+ }
491
+
477
492
// Port of MRI's `get_actual_encoding`.
478
493
public abstract static class GetActualEncodingNode extends RubyBaseNode {
479
494
Original file line number Diff line number Diff line change @@ -550,23 +550,11 @@ def inspect
550
550
ascii = enc . ascii_compatible?
551
551
unicode = Truffle . invoke_primitive :encoding_is_unicode , enc
552
552
553
- if unicode
554
- if enc . equal? Encoding ::UTF_16
555
- a = getbyte 0
556
- b = getbyte 1
557
-
558
- unless ( a == 0xfe and b == 0xff ) or ( a == 0xff and b == 0xfe )
559
- unicode = false
560
- end
561
- elsif enc . equal? Encoding ::UTF_32
562
- a = getbyte 0
563
- b = getbyte 1
564
- c = getbyte 2
565
- d = getbyte 3
566
-
567
- unless ( a == 0 and b == 0 and c == 0xfe and d == 0xfe ) or ( a == 0xff and b == 0xfe and c == 0 and d == 0 )
568
- unicode = false
569
- end
553
+ actual_encoding = enc . dummy? ? Truffle . invoke_primitive ( :get_actual_encoding , self ) : enc
554
+ if actual_encoding != enc
555
+ enc = actual_encoding
556
+ if unicode
557
+ unicode = Truffle . invoke_primitive :encoding_is_unicode , enc
570
558
end
571
559
end
572
560
You can’t perform that action at this time.
0 commit comments