Project

General

Profile

Actions

Feature #18825

closed

Specialized instruction for "array literal + `.hash`"

Added by tenderlovemaking (Aaron Patterson) over 2 years ago. Updated over 1 year ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:108877]

Description

Feature #18611 is merged. That feature encourages people to write hash methods like this:

def hash
  [@a, @b, @c].hash
end

I would like to add a specialized instruction for this case opt_newarray_hash. It's similar to opt_newarray_max and opt_newarray_min but for the hash method.

ISeqs before the optimization:

== disasm: #<ISeq:hash@test.rb:1 (1,0)-(3,3)> (catch: FALSE)
0000 getinstancevariable          :@a, <is:0>                         (   2)[LiCa]
0003 getinstancevariable          :@b, <is:1>
0006 getinstancevariable          :@c, <is:2>
0009 newarray                     3
0011 opt_send_without_block       <callinfo!mid:hash, argc:0, ARGS_SIMPLE>, <callcache>
0014 leave  

ISeqs after the optimization:

== disasm: #<ISeq:hash@test.rb:1 (1,0)-(3,3)> (catch: FALSE)
0000 getinstancevariable                    :@a, <is:0>               (   2)[LiCa]
0003 getinstancevariable                    :@b, <is:1>
0006 getinstancevariable                    :@c, <is:2>
0009 opt_newarray_hash                      3
0011 leave  

The new instruction allows us to avoid allocating a new array and also avoid pushing a stack frame.

The implementation is here, and I've also attached a patch.


Files

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0