@@ -3818,93 +3818,47 @@ def call(vm)
3818
3818
3819
3819
# ### Summary
3820
3820
#
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.
3824
3825
#
3825
3826
# ### Usage
3826
3827
#
3827
3828
# ~~~ruby
3828
3829
# [a, b, c].max
3829
3830
# ~~~
3830
3831
#
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
3861
3834
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 )
3887
3836
@number = number
3837
+ @method = method
3888
3838
end
3889
3839
3890
3840
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
+ )
3892
3845
end
3893
3846
3894
3847
def to_a ( _iseq )
3895
- [ :opt_newarray_min , number ]
3848
+ [ :opt_newarray_send , number , method ]
3896
3849
end
3897
3850
3898
3851
def deconstruct_keys ( _keys )
3899
- { number : number }
3852
+ { number : number , method : method }
3900
3853
end
3901
3854
3902
3855
def ==( other )
3903
- other . is_a? ( OptNewArrayMin ) && other . number == number
3856
+ other . is_a? ( OptNewArraySend ) && other . number == number &&
3857
+ other . method == method
3904
3858
end
3905
3859
3906
3860
def length
3907
- 2
3861
+ 3
3908
3862
end
3909
3863
3910
3864
def pops
@@ -3916,7 +3870,7 @@ def pushes
3916
3870
end
3917
3871
3918
3872
def call ( vm )
3919
- vm . push ( vm . pop ( number ) . min )
3873
+ vm . push ( vm . pop ( number ) . __send__ ( method ) )
3920
3874
end
3921
3875
end
3922
3876
0 commit comments