@@ -190,14 +190,16 @@ def inline_storage_for(name)
190
190
end
191
191
192
192
def length
193
- insns . each . inject ( 0 ) do |sum , insn |
194
- case insn
195
- when Integer , Label , Symbol
196
- sum
197
- else
198
- sum + insn . length
193
+ insns
194
+ . each
195
+ . inject ( 0 ) do |sum , insn |
196
+ case insn
197
+ when Integer , Label , Symbol
198
+ sum
199
+ else
200
+ sum + insn . length
201
+ end
199
202
end
200
- end
201
203
end
202
204
203
205
def eval
@@ -218,29 +220,32 @@ def to_a
218
220
specialize_instructions! if options . specialized_instruction?
219
221
220
222
# Next, set it up so that all of the labels get their correct name.
221
- insns . each . inject ( 0 ) do |length , insn |
222
- case insn
223
- when Integer , Symbol
224
- length
225
- when Label
226
- insn . patch! ( :"label_#{ length } " )
227
- length
228
- else
229
- length + insn . length
223
+ insns
224
+ . each
225
+ . inject ( 0 ) do |length , insn |
226
+ case insn
227
+ when Integer , Symbol
228
+ length
229
+ when Label
230
+ insn . patch! ( :"label_#{ length } " )
231
+ length
232
+ else
233
+ length + insn . length
234
+ end
230
235
end
231
- end
232
236
233
237
# Next, dump all of the instructions into a flat list.
234
- dumped = insns . each . map do |insn |
235
- case insn
236
- when Integer , Symbol
237
- insn
238
- when Label
239
- insn . name
240
- else
241
- insn . to_a ( self )
238
+ dumped =
239
+ insns . each . map do |insn |
240
+ case insn
241
+ when Integer , Symbol
242
+ insn
243
+ when Label
244
+ insn . name
245
+ else
246
+ insn . to_a ( self )
247
+ end
242
248
end
243
- end
244
249
245
250
dumped_options = argument_options . dup
246
251
dumped_options [ :opt ] . map! ( &:name ) if dumped_options [ :opt ]
@@ -271,29 +276,55 @@ def to_a
271
276
def specialize_instructions!
272
277
insns . each_node do |node |
273
278
case node . instruction
279
+ when NewArray
280
+ next unless node . next_node
281
+
282
+ next_node = node . next_node
283
+ next unless next_node . instruction . is_a? ( Send )
284
+ next if next_node . instruction . block_iseq
285
+
286
+ calldata = next_node . instruction . calldata
287
+ next unless calldata . flags == CallData ::CALL_ARGS_SIMPLE
288
+ next unless calldata . argc == 0
289
+
290
+ case calldata . method
291
+ when :max
292
+ node . instruction = OptNewArrayMax . new ( node . instruction . number )
293
+ node . next_node = next_node . next_node
294
+ when :min
295
+ node . instruction = OptNewArrayMin . new ( node . instruction . number )
296
+ node . next_node = next_node . next_node
297
+ end
274
298
when PutObject , PutString
275
299
next unless node . next_node
276
- next if node . instruction . is_a? ( PutObject ) && !node . instruction . object . is_a? ( String )
300
+ if node . instruction . is_a? ( PutObject ) &&
301
+ !node . instruction . object . is_a? ( String )
302
+ next
303
+ end
277
304
278
305
next_node = node . next_node
279
306
next unless next_node . instruction . is_a? ( Send )
280
307
next if next_node . instruction . block_iseq
281
308
282
309
calldata = next_node . instruction . calldata
283
310
next unless calldata . flags == CallData ::CALL_ARGS_SIMPLE
311
+ next unless calldata . argc == 0
284
312
285
313
case calldata . method
286
314
when :freeze
287
- node . instruction = OptStrFreeze . new ( node . instruction . object , calldata )
315
+ node . instruction =
316
+ OptStrFreeze . new ( node . instruction . object , calldata )
288
317
node . next_node = next_node . next_node
289
318
when :-@
290
- node . instruction = OptStrUMinus . new ( node . instruction . object , calldata )
319
+ node . instruction =
320
+ OptStrUMinus . new ( node . instruction . object , calldata )
291
321
node . next_node = next_node . next_node
292
322
end
293
323
when Send
294
324
calldata = node . instruction . calldata
295
325
296
- if !node . instruction . block_iseq && !calldata . flag? ( CallData ::CALL_ARGS_BLOCKARG )
326
+ if !node . instruction . block_iseq &&
327
+ !calldata . flag? ( CallData ::CALL_ARGS_BLOCKARG )
297
328
# Specialize the send instruction. If it doesn't have a block
298
329
# attached, then we will replace it with an opt_send_without_block
299
330
# and do further specializations based on the called method and
@@ -639,24 +670,6 @@ def opt_getinlinecache(label, cache)
639
670
push ( Legacy ::OptGetInlineCache . new ( label , cache ) )
640
671
end
641
672
642
- def opt_newarray_max ( length )
643
- if options . specialized_instruction?
644
- push ( OptNewArrayMax . new ( length ) )
645
- else
646
- newarray ( length )
647
- send ( YARV . calldata ( :max ) )
648
- end
649
- end
650
-
651
- def opt_newarray_min ( length )
652
- if options . specialized_instruction?
653
- push ( OptNewArrayMin . new ( length ) )
654
- else
655
- newarray ( length )
656
- send ( YARV . calldata ( :min ) )
657
- end
658
- end
659
-
660
673
def opt_setinlinecache ( cache )
661
674
push ( Legacy ::OptSetInlineCache . new ( cache ) )
662
675
end
@@ -938,9 +951,11 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
938
951
when :opt_getinlinecache
939
952
iseq . opt_getinlinecache ( labels [ opnds [ 0 ] ] , opnds [ 1 ] )
940
953
when :opt_newarray_max
941
- iseq . opt_newarray_max ( opnds [ 0 ] )
954
+ iseq . newarray ( opnds [ 0 ] )
955
+ iseq . send ( YARV . calldata ( :max ) )
942
956
when :opt_newarray_min
943
- iseq . opt_newarray_min ( opnds [ 0 ] )
957
+ iseq . newarray ( opnds [ 0 ] )
958
+ iseq . send ( YARV . calldata ( :min ) )
944
959
when :opt_neq
945
960
iseq . push (
946
961
OptNEq . new ( CallData . from ( opnds [ 0 ] ) , CallData . from ( opnds [ 1 ] ) )
0 commit comments