diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-01 00:05:33 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-01 00:05:33 +0000 |
commit | d4e28e8fd8906ad1051d61cfc01164cb3629dbb5 (patch) | |
tree | 3c6d414535225ab0eaba19095da58f0fd26371b5 /vm_eval.c | |
parent | 9664b3133048debca63163ebf01f81d916da4a1b (diff) | |
download | ruby-d4e28e8fd8906ad1051d61cfc01164cb3629dbb5.tar.gz |
rename absolute_path to realpath internally and introduce pathobj.
* vm_core.h: rename absolute_path to realpath because it is expected name.
external APIs (#absolute_path methods) are remained.
* vm_core.h: remove rb_iseq_location_struct::path and
rb_iseq_location_struct::absolute_path and introduce pathobj.
if given path equals to given absolute_path (and most of case
it is true), pathobj is simply given path String. If it is not same,
pathobj is Array and pathobj[0] is path and pathobj[1] is realpath.
This size optimization reduce 8 bytes and
sizeof(struct rb_iseq_constant_body) is 200 bytes -> 192 bytes
on 64bit CPU.
To support this change, the following functions are introduced:
* pathobj_path() (defined in vm_core.h)
* pathobj_realpath() (ditto)
* rb_iseq_path() (decl. in vm_core.h)
* rb_iseq_realpath() (ditto)
* rb_iseq_pathobj_new() (ditto)
* rb_iseq_pathobj_set() (ditto)
* vm_core.h (rb_binding_t): use pathobj instead of path. If binding
is given at eval methods, realpath (absolute_path) was caller's
realpath. However, they should use binding's realpath.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r-- | vm_eval.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -1296,20 +1296,20 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ rb_cref_t *cref = cref_arg; rb_binding_t *bind = 0; const rb_iseq_t *iseq; - VALUE absolute_path = Qnil; + VALUE realpath = Qnil; VALUE fname; if (file != Qundef) { - absolute_path = file; + realpath = file; } if (!NIL_P(scope)) { bind = Check_TypedStruct(scope, &ruby_binding_data_type); - if (NIL_P(absolute_path) && !NIL_P(bind->path)) { - file = bind->path; + if (NIL_P(realpath)) { + file = pathobj_path(bind->pathobj); + realpath = pathobj_realpath(bind->pathobj); line = bind->first_lineno; - absolute_path = rb_current_realfilepath(); } base_block = &bind->block; } @@ -1332,13 +1332,8 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ fname = rb_usascii_str_new_cstr("(eval)"); } - if (RTEST(fname)) - fname = rb_fstring(fname); - if (RTEST(absolute_path)) - absolute_path = rb_fstring(absolute_path); - /* make eval iseq */ - iseq = rb_iseq_compile_with_option(src, fname, absolute_path, INT2FIX(line), base_block, Qnil); + iseq = rb_iseq_compile_with_option(src, fname, realpath, INT2FIX(line), base_block, Qnil); if (!iseq) { rb_exc_raise(adjust_backtrace_in_eval(th, th->errinfo)); @@ -2180,7 +2175,7 @@ rb_current_realfilepath(void) rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = th->ec.cfp; cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); - if (cfp != 0) return cfp->iseq->body->location.absolute_path; + if (cfp != 0) return rb_iseq_realpath(cfp->iseq); return Qnil; } |