fastruby / fast-ruby

:dash: Writing Fast Ruby :heart_eyes: -- Collect Common Ruby idioms.
https://github.com/fastruby/fast-ruby
5.67k stars 376 forks source link

Fix unused variable warnings #66

Closed yous closed 9 years ago

yous commented 9 years ago

Fix #36.

yous commented 9 years ago

Seems there is no modification of instructions:

$ ruby --dump=insns -e 'def fast; a, b, c = 1, 2, 3; nil; end'
== disasm: <RubyVM::InstructionSequence:<main>@-e>======================
0000 trace            1                                               (   1)
0002 putspecialobject 1
0004 putspecialobject 2
0006 putobject        :fast
0008 putiseq          fast
0010 opt_send_without_block <callinfo!mid:core#define_method, argc:3, ARGS_SIMPLE>
0012 leave
== disasm: <RubyVM::InstructionSequence:fast@-e>========================
local table (size: 4, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 4] a          [ 3] b          [ 2] c
0000 trace            8                                               (   1)
0002 trace            1
0004 putobject_OP_INT2FIX_O_1_C_
0005 putobject        2
0007 putobject        3
0009 setlocal_OP__WC__0 2
0011 setlocal_OP__WC__0 3
0013 setlocal_OP__WC__0 4
0015 putnil
0016 trace            16
0018 leave
$ ruby --dump=insns -e 'def fast; _a, _b, _c = 1, 2, 3; nil; end'
== disasm: <RubyVM::InstructionSequence:<main>@-e>======================
0000 trace            1                                               (   1)
0002 putspecialobject 1
0004 putspecialobject 2
0006 putobject        :fast
0008 putiseq          fast
0010 opt_send_without_block <callinfo!mid:core#define_method, argc:3, ARGS_SIMPLE>
0012 leave
== disasm: <RubyVM::InstructionSequence:fast@-e>========================
local table (size: 4, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 4] _a         [ 3] _b         [ 2] _c
0000 trace            8                                               (   1)
0002 trace            1
0004 putobject_OP_INT2FIX_O_1_C_
0005 putobject        2
0007 putobject        3
0009 setlocal_OP__WC__0 2
0011 setlocal_OP__WC__0 3
0013 setlocal_OP__WC__0 4
0015 putnil
0016 trace            16
0018 leave
$ diff <(ruby --dump=insns -e 'def fast; a, b, c = 1, 2, 3; nil; end') <(ruby --dump=insns -e 'def fast; _a, _b, _c = 1, 2, 3; nil; end')
11c11
< [ 4] a          [ 3] b          [ 2] c
---
> [ 4] _a         [ 3] _b         [ 2] _c
JuanitoFatas commented 9 years ago

Awesome! :clap: :clap: :clap: