diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-12 20:57:45 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-12 20:57:45 +0000 |
commit | ec475ab32d7ba876c1ce96f9ce6704d85be6a3ac (patch) | |
tree | c1e36b00698f99185e91d1e9d432f7372e00c28d /proc.c | |
parent | afa512d9e18d39b2e727a0ee1a792f21505779bb (diff) |
proc.c (rb_proc_alloc): inline and move to vm.c
* proc.c (rb_proc_alloc): inline and move to vm.c
(rb_proc_wrap): new wrapper function used by rb_proc_alloc
(proc_dup): simplify alloc + copy + wrap operation
[ruby-core:64994]
* vm.c (rb_proc_alloc): new inline function
(rb_vm_make_proc): call rb_proc_alloc
* vm_core.h: remove rb_proc_alloc, add rb_proc_wrap
* benchmark/bm_vm2_newlambda.rb: short test to show difference
First we allocate and populate an rb_proc_t struct inline to avoid
unnecessary zeroing of the large struct. Inlining speeds up callers as
this takes many parameters to ensure correctness. We then call the new
rb_proc_wrap function to create the object.
rb_proc_wrap - wraps a rb_proc_t pointer as a Ruby object, but
we only use it inside rb_proc_alloc. We must call this before
the compiler may clobber VALUE parameters passed to rb_proc_alloc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -84,10 +84,11 @@ static const rb_data_type_t proc_data_type = { }; VALUE -rb_proc_alloc(VALUE klass) +rb_proc_wrap(VALUE klass, rb_proc_t *proc) { - rb_proc_t *proc; - return TypedData_Make_Struct(klass, rb_proc_t, &proc_data_type, proc); + proc->block.proc = TypedData_Wrap_Struct(klass, &proc_data_type, proc); + + return proc->block.proc; } VALUE @@ -105,17 +106,14 @@ rb_obj_is_proc(VALUE proc) static VALUE proc_dup(VALUE self) { - VALUE procval = rb_proc_alloc(rb_cProc); - rb_proc_t *src, *dst; + VALUE procval; + rb_proc_t *src; + rb_proc_t *dst = ALLOC(rb_proc_t); + GetProcPtr(self, src); - GetProcPtr(procval, dst); - - dst->block = src->block; - dst->block.proc = procval; - dst->blockprocval = src->blockprocval; - dst->envval = src->envval; - dst->safe_level = src->safe_level; - dst->is_lambda = src->is_lambda; + *dst = *src; + procval = rb_proc_wrap(rb_cProc, dst); + RB_GC_GUARD(self); /* for: body = proc_dup(body) */ return procval; } |