@@ -541,20 +541,23 @@ def transform_values!
541
541
542
542
def transform_keys ( mapping = nil )
543
543
has_block = block_given?
544
- return to_enum ( :transform_keys ) { size } unless mapping || has_block
545
-
546
- mapping = Truffle ::Type . coerce_to ( mapping , Hash , :to_hash ) if mapping
547
-
548
544
h = { }
549
- each_pair do |key , value |
550
- if mapping
545
+
546
+ if mapping
547
+ mapping = Truffle ::Type . coerce_to ( mapping , Hash , :to_hash )
548
+ each_pair do |key , value |
551
549
k = Primitive . hash_get_or_undefined ( mapping , key )
552
550
k = has_block ? yield ( key ) : key if Primitive . undefined? ( k )
553
551
h [ k ] = value
554
- else
552
+ end
553
+ else
554
+ return to_enum ( :transform_keys ) { size } unless has_block
555
+
556
+ each_pair do |key , value |
555
557
h [ yield ( key ) ] = value
556
558
end
557
559
end
560
+
558
561
h
559
562
end
560
563
@@ -563,16 +566,18 @@ def transform_keys!(mapping = nil)
563
566
return to_enum ( :transform_keys! ) { size } unless mapping || has_block
564
567
565
568
Primitive . check_frozen self
566
- mapping = Truffle ::Type . coerce_to ( mapping , Hash , :to_hash ) if mapping
567
-
568
569
h = { }
570
+
569
571
begin
570
- each_pair do |key , value |
571
- if mapping
572
+ if mapping
573
+ mapping = Truffle ::Type . coerce_to ( mapping , Hash , :to_hash )
574
+ each_pair do |key , value |
572
575
k = Primitive . hash_get_or_undefined ( mapping , key )
573
576
k = has_block ? yield ( key ) : key if Primitive . undefined? ( k )
574
577
h [ k ] = value
575
- else
578
+ end
579
+ else
580
+ each_pair do |key , value |
576
581
h [ yield ( key ) ] = value
577
582
end
578
583
end
0 commit comments