Created
November 8, 2013 16:02
-
-
Save ashmoran/7373241 to your computer and use it in GitHub Desktop.
Disassembled YARV versions of various nil checks in Ruby 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
"true unless nil.nil?", | |
"true if nil != nil", | |
"true if !!nil", | |
"true unless nil" | |
].each do |source| | |
puts "=====" | |
puts source | |
puts | |
puts RubyVM::InstructionSequence.compile(source).disasm | |
puts "=====" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
===== | |
true unless nil.nil? | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 putnil | |
0003 opt_send_simple <callinfo!mid:nil?, argc:0, ARGS_SKIP> | |
0005 branchunless 10 | |
0007 putnil | |
0008 leave | |
0009 pop | |
0010 putobject true | |
0012 leave | |
===== | |
===== | |
true if nil != nil | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 putnil | |
0003 putnil | |
0004 opt_neq <callinfo!mid:!=, argc:1, ARGS_SKIP>, <callinfo!mid:==, argc:1, ARGS_SKIP> | |
0007 branchunless 13 | |
0009 putobject true | |
0011 leave | |
0012 pop | |
0013 putnil | |
0014 leave | |
===== | |
===== | |
true if !!nil | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 putnil | |
0003 opt_not <callinfo!mid:!, argc:0, ARGS_SKIP> | |
0005 opt_not <callinfo!mid:!, argc:0, ARGS_SKIP> | |
0007 branchunless 13 | |
0009 putobject true | |
0011 leave | |
0012 pop | |
0013 putnil | |
0014 leave | |
===== | |
===== | |
true unless nil | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 jump 7 | |
0004 putnil | |
0005 leave | |
0006 pop | |
0007 putobject true | |
0009 leave | |
===== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment