Created
August 30, 2016 03:41
-
-
Save hibariya/eb0225db8de6ca06e0739f2ffb348af2 to your computer and use it in GitHub Desktop.
I never knew 'literal'.freeze is compiled in 1 instruction (not 2)
This file contains hidden or 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
# 1 instruction | |
puts RubyVM::InstructionSequence.compile(%('hi')).disasm | |
# == disasm: #<ISeq:<compiled>@<compiled>>================================ | |
# 0000 trace 1 ( 1) | |
# 0002 putstring "hi" | |
# 0004 leave | |
# 1 instruction | |
puts RubyVM::InstructionSequence.compile(%('hi'.freeze)).disasm | |
# == disasm: #<ISeq:<compiled>@<compiled>>================================ | |
# 0000 trace 1 ( 1) | |
# 0002 opt_str_freeze "hi" | |
# 0004 leave | |
# 3 instructions | |
puts RubyVM::InstructionSequence.compile(%('hi'.itself.freeze)).disasm | |
# == disasm: #<ISeq:<compiled>@<compiled>>================================ | |
# 0000 trace 1 ( 1) | |
# 0002 putstring "hi" | |
# 0004 opt_send_without_block <callinfo!mid:itself, argc:0, ARGS_SIMPLE>, <callcache> | |
# 0007 opt_send_without_block <callinfo!mid:freeze, argc:0, ARGS_SIMPLE>, <callcache> | |
# 0010 leave |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment