avoid unnecessary pool/syms restoration

parent 7320139f
......@@ -126,6 +126,9 @@ fiber_result(mrb_state *mrb, mrb_value *a, int len)
return mrb_ary_new_from_values(mrb, len, a);
}
/* mark return from context modifying method */
#define MARK_CONTEXT_MODIFY(c) (c)->ci->target_class = NULL
/*
* call-seq:
* fiber.resume(args, ...) -> obj
......@@ -160,11 +163,13 @@ fiber_resume(mrb_state *mrb, mrb_value self)
c->prev = mrb->c;
mrb->c = c;
MARK_CONTEXT_MODIFY(c);
return c->ci->proc->env->stack[0];
}
if (c->ci == c->cibase) {
mrb_raise(mrb, E_RUNTIME_ERROR, "resuming dead fiber");
}
MARK_CONTEXT_MODIFY(c);
c->prev = mrb->c;
mrb->c = c;
return fiber_result(mrb, a, len);
......@@ -193,6 +198,7 @@ fiber_yield(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "*", &a, &len);
mrb->c = c->prev;
MARK_CONTEXT_MODIFY(mrb->c);
return fiber_result(mrb, a, len);
}
......
......@@ -920,10 +920,12 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
if (mrb->exc) goto L_RAISE;
/* pop stackpos */
ci = mrb->c->ci;
if (!MRB_PROC_CFUNC_P(ci[-1].proc)) {
irep = ci[-1].proc->body.irep;
pool = irep->pool;
syms = irep->syms;
if (!ci->target_class) { /* return from context modifying method (resume/yield) */
if (!MRB_PROC_CFUNC_P(ci[-1].proc)) {
irep = ci[-1].proc->body.irep;
pool = irep->pool;
syms = irep->syms;
}
}
regs = mrb->c->stack = mrb->c->stbase + ci->stackidx;
pc = ci->pc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment