@@ -3818,93 +3818,47 @@ def call(vm)
38183818
38193819 # ### Summary
38203820 #
3821- # `opt_newarray_max` is a specialization that occurs when the `max` method
3822- # is called on an array literal. It pops the values of the array off the
3823- # stack and pushes on the result.
3821+ # `opt_newarray_send` is a specialization that occurs when a dynamic array
3822+ # literal is created and immediately sent the `min`, `max`, or `hash`
3823+ # methods. It pops the values of the array off the stack and pushes on the
3824+ # result of the method call.
38243825 #
38253826 # ### Usage
38263827 #
38273828 # ~~~ruby
38283829 # [a, b, c].max
38293830 # ~~~
38303831 #
3831- class OptNewArrayMax < Instruction
3832- attr_reader :number
3833-
3834- def initialize ( number )
3835- @number = number
3836- end
3837-
3838- def disasm ( fmt )
3839- fmt . instruction ( "opt_newarray_max" , [ fmt . object ( number ) ] )
3840- end
3841-
3842- def to_a ( _iseq )
3843- [ :opt_newarray_max , number ]
3844- end
3845-
3846- def deconstruct_keys ( _keys )
3847- { number : number }
3848- end
3849-
3850- def ==( other )
3851- other . is_a? ( OptNewArrayMax ) && other . number == number
3852- end
3853-
3854- def length
3855- 2
3856- end
3857-
3858- def pops
3859- number
3860- end
3832+ class OptNewArraySend < Instruction
3833+ attr_reader :number , :method
38613834
3862- def pushes
3863- 1
3864- end
3865-
3866- def call ( vm )
3867- vm . push ( vm . pop ( number ) . max )
3868- end
3869- end
3870-
3871- # ### Summary
3872- #
3873- # `opt_newarray_min` is a specialization that occurs when the `min` method
3874- # is called on an array literal. It pops the values of the array off the
3875- # stack and pushes on the result.
3876- #
3877- # ### Usage
3878- #
3879- # ~~~ruby
3880- # [a, b, c].min
3881- # ~~~
3882- #
3883- class OptNewArrayMin < Instruction
3884- attr_reader :number
3885-
3886- def initialize ( number )
3835+ def initialize ( number , method )
38873836 @number = number
3837+ @method = method
38883838 end
38893839
38903840 def disasm ( fmt )
3891- fmt . instruction ( "opt_newarray_min" , [ fmt . object ( number ) ] )
3841+ fmt . instruction (
3842+ "opt_newarray_send" ,
3843+ [ fmt . object ( number ) , fmt . object ( method ) ]
3844+ )
38923845 end
38933846
38943847 def to_a ( _iseq )
3895- [ :opt_newarray_min , number ]
3848+ [ :opt_newarray_send , number , method ]
38963849 end
38973850
38983851 def deconstruct_keys ( _keys )
3899- { number : number }
3852+ { number : number , method : method }
39003853 end
39013854
39023855 def ==( other )
3903- other . is_a? ( OptNewArrayMin ) && other . number == number
3856+ other . is_a? ( OptNewArraySend ) && other . number == number &&
3857+ other . method == method
39043858 end
39053859
39063860 def length
3907- 2
3861+ 3
39083862 end
39093863
39103864 def pops
@@ -3916,7 +3870,7 @@ def pushes
39163870 end
39173871
39183872 def call ( vm )
3919- vm . push ( vm . pop ( number ) . min )
3873+ vm . push ( vm . pop ( number ) . __send__ ( method ) )
39203874 end
39213875 end
39223876
0 commit comments