aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authorcharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-09 21:17:06 +0000
committercharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-09 21:17:06 +0000
commit07ac58747f84412ea476b911fd25219093c581ed (patch)
tree6d1a97aa0c4f5e55f767ea4f602da32b894a393c /compile.c
parentd6f5e30df87b4dfa4d66d8f4cb74da7dde949e8d (diff)
downloadruby-07ac58747f84412ea476b911fd25219093c581ed.tar.gz
* compile.c (iseq_compile_each): emit opt_str_freeze if the #freeze
method is called on a static string literal with no arguments. * defs/id.def (firstline): add freeze so idFreeze is available * insns.def (opt_str_freeze): add opt_str_freeze instruction which pushes a frozen string literal without allocating a new object if String#freeze is not overriden * string.c (Init_String): define String#freeze * vm.c (vm_init_redefined_flag): define BOP_FREEZE on String class as a basic operation * vm_insnhelper.h: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index f3f5f2d75a..00ae3011e7 100644
--- a/compile.c
+++ b/compile.c
@@ -4314,6 +4314,17 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
break;
}
case NODE_CALL:
+ if (node->nd_recv && nd_type(node->nd_recv) == NODE_STR &&
+ node->nd_mid == idFreeze && node->nd_args == NULL)
+ {
+ VALUE str = rb_fstring(node->nd_recv->nd_lit);
+ iseq_add_mark_object(iseq, str);
+ ADD_INSN1(ret, line, opt_str_freeze, str);
+ if (poped) {
+ ADD_INSN(ret, line, pop);
+ }
+ break;
+ }
case NODE_FCALL:
case NODE_VCALL:{ /* VCALL: variable or call */
/*