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 | 478003f6df40dc79d33c6ec86919f2dde07284be (patch) | |
tree | 3c6d414535225ab0eaba19095da58f0fd26371b5 /vm.c | |
parent | d0015e4ac6b812ea1681b1f5fa86fbab52a58960 (diff) | |
download | ruby-478003f6df40dc79d33c6ec86919f2dde07284be.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.c')
-rw-r--r-- | vm.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -902,7 +902,7 @@ rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp) vm_bind_update_env(bind, envval); bind->block.as.captured.self = cfp->self; bind->block.as.captured.code.iseq = cfp->iseq; - bind->path = ruby_level_cfp->iseq->body->location.path; + bind->pathobj = ruby_level_cfp->iseq->body->location.pathobj; bind->first_lineno = rb_vm_get_sourceline(ruby_level_cfp); return bindval; @@ -911,7 +911,9 @@ rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp) const VALUE * rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars) { - VALUE envval, path = bind->path; + VALUE envval, pathobj = bind->pathobj; + VALUE path = pathobj_path(pathobj); + VALUE realpath = pathobj_realpath(pathobj); const struct rb_block *base_block; const rb_env_t *env; rb_thread_t *th = GET_THREAD(); @@ -932,7 +934,7 @@ rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars) node = NEW_NODE(NODE_SCOPE, dyns, 0, 0); if (base_iseq) { - iseq = rb_iseq_new(node, base_iseq->body->location.label, path, path, base_iseq, ISEQ_TYPE_EVAL); + iseq = rb_iseq_new(node, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL); } else { VALUE tempstr = rb_fstring_cstr("<temp>"); @@ -1234,7 +1236,7 @@ rb_sourcefilename(void) rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->ec.cfp); if (cfp) { - return cfp->iseq->body->location.path; + return rb_iseq_path(cfp->iseq); } else { return Qnil; @@ -1248,7 +1250,7 @@ rb_sourcefile(void) rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->ec.cfp); if (cfp) { - return RSTRING_PTR(cfp->iseq->body->location.path); + return RSTRING_PTR(rb_iseq_path(cfp->iseq)); } else { return 0; @@ -1277,7 +1279,7 @@ rb_source_location(int *pline) if (cfp) { if (pline) *pline = rb_vm_get_sourceline(cfp); - return cfp->iseq->body->location.path; + return rb_iseq_path(cfp->iseq); } else { if (pline) *pline = 0; @@ -2060,7 +2062,7 @@ rb_thread_current_status(const rb_thread_t *th) const rb_iseq_t *iseq = cfp->iseq; int line_no = rb_vm_get_sourceline(cfp); str = rb_sprintf("%"PRIsVALUE":%d:in `%"PRIsVALUE"'", - iseq->body->location.path, line_no, iseq->body->location.label); + rb_iseq_path(iseq), line_no, iseq->body->location.label); } } else if ((me = rb_vm_frame_method_entry(cfp)) && me->def->original_id) { @@ -3085,7 +3087,8 @@ rb_vm_set_progname(VALUE filename) rb_thread_t *th = GET_VM()->main_thread; rb_control_frame_t *cfp = (void *)(th->ec.stack + th->ec.stack_size); --cfp; - RB_OBJ_WRITE(cfp->iseq, &cfp->iseq->body->location.path, filename); + + rb_iseq_pathobj_set(cfp->iseq, rb_str_dup(filename), rb_iseq_realpath(cfp->iseq)); } extern const struct st_hash_type rb_fstring_hash_type; |