summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-12 20:57:45 (GMT)
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-12 20:57:45 (GMT)
commitec475ab32d7ba876c1ce96f9ce6704d85be6a3ac (patch)
treec1e36b00698f99185e91d1e9d432f7372e00c28d /vm.c
parentafa512d9e18d39b2e727a0ee1a792f21505779bb (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 'vm.c')
-rw-r--r--vm.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/vm.c b/vm.c
index f5fb5a7..7591f97 100644
--- a/vm.c
+++ b/vm.c
@@ -651,11 +651,35 @@ vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block)
return block->proc;
}
+static inline VALUE
+rb_proc_alloc(VALUE klass, const rb_block_t *block,
+ VALUE envval, VALUE blockprocval,
+ int8_t safe_level, int8_t is_from_method, int8_t is_lambda)
+{
+ VALUE procval;
+ rb_proc_t *proc = ALLOC(rb_proc_t);
+
+ proc->block = *block;
+ proc->safe_level = safe_level;
+ proc->is_from_method = is_from_method;
+ proc->is_lambda = is_lambda;
+
+ procval = rb_proc_wrap(klass, proc);
+
+ /*
+ * ensure VALUEs are markable here as rb_proc_wrap may trigger allocation
+ * and clobber envval + blockprocval
+ */
+ proc->envval = envval;
+ proc->blockprocval = blockprocval;
+
+ return procval;
+}
+
VALUE
rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass)
{
VALUE procval, envval, blockprocval = 0;
- rb_proc_t *proc;
rb_control_frame_t *cfp = RUBY_VM_GET_CFP_FROM_BLOCK_PTR(block);
if (block->proc) {
@@ -667,16 +691,9 @@ rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass)
if (PROCDEBUG) {
check_env_value(envval);
}
- procval = rb_proc_alloc(klass);
- GetProcPtr(procval, proc);
- proc->blockprocval = blockprocval;
- proc->block.self = block->self;
- proc->block.klass = block->klass;
- proc->block.ep = block->ep;
- proc->block.iseq = block->iseq;
- proc->block.proc = procval;
- proc->envval = envval;
- proc->safe_level = th->safe_level;
+
+ procval = rb_proc_alloc(klass, block, envval, blockprocval,
+ th->safe_level, 0, 0);
if (VMDEBUG) {
if (th->stack < block->ep && block->ep < th->stack + th->stack_size) {