@@ -507,34 +507,27 @@ def inspect
507
507
end
508
508
end
509
509
510
- array = [ ]
510
+ result = '"' . dup . force_encoding ( result_encoding )
511
511
512
512
index = 0
513
513
total = bytesize
514
514
while index < total
515
515
char = Primitive . string_chr_at ( self , index )
516
516
517
517
if char
518
- index += inspect_char ( enc , result_encoding , ascii , unicode , index , char , array )
518
+ index += inspect_char ( enc , result_encoding , ascii , unicode , index , char , result )
519
519
else
520
- array << "\\ x#{ getbyte ( index ) . to_s ( 16 ) . upcase } "
520
+ result << "\\ x#{ getbyte ( index ) . to_s ( 16 ) . upcase } "
521
521
index += 1
522
522
end
523
523
end
524
524
525
- size = array . inject ( 0 ) { |s , chr | s + chr . bytesize }
526
- result = String . pattern size + 2 , ?". ord
527
-
528
- index = 1
529
- array . each do |chr |
530
- Truffle ::StringOperations . copy_from ( result , chr , 0 , chr . bytesize , index )
531
- index += chr . bytesize
532
- end
525
+ result << '"'
533
526
534
527
result . force_encoding ( result_encoding )
535
528
end
536
529
537
- def inspect_char ( enc , result_encoding , ascii , unicode , index , char , array )
530
+ private def inspect_char ( enc , result_encoding , ascii , unicode , index , char , result )
538
531
consumed = char . bytesize
539
532
540
533
if ( ascii or unicode ) and consumed == 1
@@ -578,38 +571,37 @@ def inspect_char(enc, result_encoding, ascii, unicode, index, char, array)
578
571
end
579
572
580
573
if escaped
581
- array << escaped
574
+ result << escaped
582
575
return consumed
583
576
end
584
577
end
585
578
end
586
579
587
580
if Primitive . character_printable_p ( char ) && ( enc == result_encoding || ( ascii && char . ascii_only? ) )
588
- array << char
581
+ result << char
589
582
else
590
583
code = char . ord
591
584
escaped = code . to_s ( 16 ) . upcase
592
585
593
586
if unicode
594
587
if code < 0x10000
595
588
pad = '0' * ( 4 - escaped . bytesize )
596
- array << "\\ u#{ pad } #{ escaped } "
589
+ result << "\\ u#{ pad } #{ escaped } "
597
590
else
598
- array << "\\ u{#{ escaped } }"
591
+ result << "\\ u{#{ escaped } }"
599
592
end
600
593
else
601
594
if code < 0x100
602
595
pad = '0' * ( 2 - escaped . bytesize )
603
- array << "\\ x#{ pad } #{ escaped } "
596
+ result << "\\ x#{ pad } #{ escaped } "
604
597
else
605
- array << "\\ x{#{ escaped } }"
598
+ result << "\\ x{#{ escaped } }"
606
599
end
607
600
end
608
601
end
609
602
610
603
consumed
611
604
end
612
- private :inspect_char
613
605
614
606
def prepend ( *others )
615
607
if others . size == 1
0 commit comments