From 1282a4a89500f3c45f0cd56623d536f40abe9bb6 Mon Sep 17 00:00:00 2001 From: normal Date: Tue, 26 Jan 2016 06:23:47 +0000 Subject: [PATCH] fstring early for internal iseq All of the strings created here eventually get converted to fstrings when they are frozen into the iseq. Prepare the fstring early so we may reduce a one or two objects. This is a very minor change, mainly for the '
' dedupe. * compile.c (caller_location): use rb_fstring_cstr for "" (it is converted to fstring anyways inside rb_iseq_new_with_opt) * iseq.c (iseqw_s_compile): ditto * iseq.c (rb_iseq_new_main): use rb_fstring_cstr for "
" * vm.c (Init_VM): ditto, share with with above * iseq.c (iseqw_s_compile_file): rb_fstring before rb_io_t->pathv share "
" with above * vm.c (rb_binding_add_dynavars): fstring "" immediately git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ compile.c | 2 +- iseq.c | 13 ++++++++----- vm.c | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d08a6e0a55..3e155ca3ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Jan 26 15:21:37 2016 Eric Wong + + * compile.c (caller_location): use rb_fstring_cstr for "" + (it is converted to fstring anyways inside rb_iseq_new_with_opt) + * iseq.c (iseqw_s_compile): ditto + * iseq.c (rb_iseq_new_main): use rb_fstring_cstr for "
" + * vm.c (Init_VM): ditto, share with with above + * iseq.c (iseqw_s_compile_file): rb_fstring before rb_io_t->pathv + share "
" with above + * vm.c (rb_binding_add_dynavars): fstring "" immediately + Tue Jan 26 15:14:01 2016 Kazuki Yamaguchi * compile.c (iseq_peephole_optimize): don't apply tailcall diff --git a/compile.c b/compile.c index ea9b4905ad..aee1b4ed93 100644 --- a/compile.c +++ b/compile.c @@ -6748,7 +6748,7 @@ caller_location(VALUE *path, VALUE *absolute_path) return line; } else { - *path = rb_str_new2(""); + *path = rb_fstring_cstr(""); *absolute_path = *path; return 1; } diff --git a/iseq.c b/iseq.c index b8ae57b782..3d1713c6be 100644 --- a/iseq.c +++ b/iseq.c @@ -442,7 +442,8 @@ rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path) { rb_thread_t *th = GET_THREAD(); const rb_iseq_t *parent = th->base_block->iseq; - return rb_iseq_new_with_opt(node, rb_str_new2("
"), path, absolute_path, INT2FIX(0), + return rb_iseq_new_with_opt(node, rb_fstring_cstr("
"), + path, absolute_path, INT2FIX(0), parent, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT); } @@ -774,7 +775,7 @@ iseqw_s_compile(int argc, VALUE *argv, VALUE self) rb_secure(1); rb_scan_args(argc, argv, "14", &src, &file, &path, &line, &opt); - if (NIL_P(file)) file = rb_str_new2(""); + if (NIL_P(file)) file = rb_fstring_cstr(""); if (NIL_P(line)) line = INT2FIX(1); return iseqw_new(rb_iseq_compile_with_option(src, file, path, line, 0, opt)); @@ -813,6 +814,7 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self) rb_secure(1); rb_scan_args(argc, argv, "11", &file, &opt); FilePathValue(file); + file = rb_fstring(file); /* rb_io_t->pathv gets frozen anyways */ fname = StringValueCStr(file); f = rb_file_open_str(file, "r"); @@ -824,9 +826,10 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self) make_compile_option(&option, opt); - return iseqw_new(rb_iseq_new_with_opt(node, rb_str_new2("
"), file, - rb_realpath_internal(Qnil, file, 1), line, NULL, - ISEQ_TYPE_TOP, &option)); + return iseqw_new(rb_iseq_new_with_opt(node, rb_fstring_cstr("
"), + file, + rb_realpath_internal(Qnil, file, 1), + line, NULL, ISEQ_TYPE_TOP, &option)); } /* diff --git a/vm.c b/vm.c index 58ed56b993..a577b0922e 100644 --- a/vm.c +++ b/vm.c @@ -885,7 +885,7 @@ rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars) iseq = rb_iseq_new(node, base_iseq->body->location.label, path, path, base_iseq, ISEQ_TYPE_EVAL); } else { - VALUE tempstr = rb_str_new2(""); + VALUE tempstr = rb_fstring_cstr(""); iseq = rb_iseq_new_top(node, tempstr, tempstr, tempstr, NULL); } node->u1.tbl = 0; /* reset table */ @@ -2911,7 +2911,7 @@ Init_VM(void) { rb_vm_t *vm = ruby_current_vm; rb_thread_t *th = GET_THREAD(); - VALUE filename = rb_str_new2("
"); + VALUE filename = rb_fstring_cstr("
"); const rb_iseq_t *iseq = rb_iseq_new(0, filename, filename, Qnil, 0, ISEQ_TYPE_TOP); volatile VALUE th_self;