Commit cc71bd51 authored by Tatsuhiko Kubo's avatar Tatsuhiko Kubo Committed by Yukihiro "Matz" Matsumoto

optimize Proc#parameters

parent 94b73b14
...@@ -94,20 +94,21 @@ static mrb_value ...@@ -94,20 +94,21 @@ static mrb_value
mrb_proc_parameters(mrb_state *mrb, mrb_value self) mrb_proc_parameters(mrb_state *mrb, mrb_value self)
{ {
struct parameters_type { struct parameters_type {
int size; size_t len;
const char *name; const char *name;
int size;
} *p, parameters_list [] = { } *p, parameters_list [] = {
{0, "req"}, {sizeof("req") - 1, "req", 0},
{0, "opt"}, {sizeof("opt") - 1, "opt", 0},
{0, "rest"}, {sizeof("rest") - 1, "rest", 0},
{0, "req"}, {sizeof("req") - 1, "req", 0},
{0, "block"}, {sizeof("block") - 1, "block", 0},
{0, NULL} {0, NULL, 0}
}; };
const struct RProc *proc = mrb_proc_ptr(self); const struct RProc *proc = mrb_proc_ptr(self);
const struct mrb_irep *irep = proc->body.irep; const struct mrb_irep *irep = proc->body.irep;
mrb_aspec aspec; mrb_aspec aspec;
mrb_value sname, parameters; mrb_value parameters;
int i, j; int i, j;
int max = -1; int max = -1;
...@@ -126,7 +127,9 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self) ...@@ -126,7 +127,9 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
} }
if (!MRB_PROC_STRICT_P(proc)) { if (!MRB_PROC_STRICT_P(proc)) {
parameters_list[0].len = sizeof("opt") - 1;
parameters_list[0].name = "opt"; parameters_list[0].name = "opt";
parameters_list[3].len = sizeof("opt") - 1;
parameters_list[3].name = "opt"; parameters_list[3].name = "opt";
} }
...@@ -141,8 +144,8 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self) ...@@ -141,8 +144,8 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
max = irep->nlocals-1; max = irep->nlocals-1;
for (i = 0, p = parameters_list; p->name; p++) { for (i = 0, p = parameters_list; p->name; p++) {
if (p->size <= 0) continue; mrb_value sname = mrb_symbol_value(mrb_intern_static(mrb, p->name, p->len));
sname = mrb_symbol_value(mrb_intern_cstr(mrb, p->name));
for (j = 0; j < p->size; i++, j++) { for (j = 0; j < p->size; i++, j++) {
mrb_value a; mrb_value a;
......
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