From e5dde46c7cbc65e12461a2d67f51cc61470a1902 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 18 Aug 2012 19:29:07 +0900 Subject: reduce mrb_funcall invocations --- src/array.c | 5 ++++- src/error.c | 2 +- src/re.c | 4 +--- src/string.c | 1 - src/variable.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/array.c b/src/array.c index 804c946da..15b6df0f2 100644 --- a/src/array.c +++ b/src/array.c @@ -290,12 +290,15 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1) a1 = RARRAY(ary1); a2 = RARRAY(ary2); if (a1->len == a2->len && a1->ptr == a2->ptr) return mrb_fixnum_value(0); else { + mrb_sym cmp = mrb_intern(mrb, "<=>"); + len = RARRAY_LEN(ary1); if (len > RARRAY_LEN(ary2)) { len = RARRAY_LEN(ary2); } for (i=0; i", 1, ary_elt(ary2, i)); + mrb_value v = ary_elt(ary2, i); + r = mrb_funcall_argv(mrb, ary_elt(ary1, i), cmp, 1, &v); if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r; } } diff --git a/src/error.c b/src/error.c index 150524f87..fd17e6697 100644 --- a/src/error.c +++ b/src/error.c @@ -277,7 +277,7 @@ sysexit_status(mrb_state *mrb, mrb_value err) static void set_backtrace(mrb_state *mrb, mrb_value info, mrb_value bt) { - mrb_funcall(mrb, info, "set_backtrace", 1, bt); + mrb_funcall(mrb, info, "set_backtrace", 1, bt); } mrb_value diff --git a/src/re.c b/src/re.c index 0022f9a9c..ff637aecb 100644 --- a/src/re.c +++ b/src/re.c @@ -65,8 +65,6 @@ static char * option_to_str(char str[4], int options); mrb_value mrb_reg_s_new_instance(mrb_state *mrb, /*int argc, mrb_value *argv, */mrb_value self) { - //obj = mrb_obj_alloc(klass); - //mrb_obj_call_init(obj, argc, argv);...mrb_funcall2(obj, idInitialize, argc, argv); mrb_value argv[16]; int argc; struct RRegexp *re; @@ -76,7 +74,7 @@ mrb_reg_s_new_instance(mrb_state *mrb, /*int argc, mrb_value *argv, */mrb_value re->ptr = 0; re->src = 0; re->usecnt = 0; - return mrb_funcall_argv(mrb, mrb_obj_value(re), mrb_intern(mrb, "initialize"), argc, argv); + return mrb_funcall_argv(mrb, mrb_obj_value(re), mrb->init_sym, argc, argv); } mrb_value diff --git a/src/string.c b/src/string.c index b749614dc..a454aab97 100644 --- a/src/string.c +++ b/src/string.c @@ -1721,7 +1721,6 @@ mrb_str_match_m(mrb_state *mrb, mrb_value self) mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%d for 1..2)", argc); re = argv[0]; argv[0] = self; - // result = mrb_funcall2(get_pat(re, 0), mrb_intern("match"), argc, argv); result = mrb_funcall(mrb, get_pat(mrb, re, 0), "match", 1, self); if (!mrb_nil_p(result) && mrb_block_given_p()) { return mrb_yield(mrb, b, result); diff --git a/src/variable.c b/src/variable.c index 1fb91c56c..e5ab73d6c 100644 --- a/src/variable.c +++ b/src/variable.c @@ -708,7 +708,7 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) while (c) { if (mrb_respond_to(mrb, mrb_obj_value(c), cm)) { mrb_value name = mrb_symbol_value(sym); - return mrb_funcall(mrb, mrb_obj_value(c), "const_missing", 1, name); + return mrb_funcall_argv(mrb, mrb_obj_value(c), cm, 1, &name); } c = c->super; } -- cgit v1.2.3