diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-19 23:53:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-19 23:53:12 +0000 |
commit | 24da2db3e1eab67b6ee7be00d75b73beb273a4c4 (patch) | |
tree | c9885fd321617b032fefc19e873ae1a6c8e83189 /vm_method.c | |
parent | 82da3da5aca885fc7995c426696cb7798faad3d6 (diff) |
vm_method.c: reuse method entry
* vm_method.c (rb_obj_respond_to): reuse found method entry
instead of searching same entry repeatedly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/vm_method.c b/vm_method.c index f03d312d97..fd000fa95a 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1833,22 +1833,28 @@ int rb_obj_respond_to(VALUE obj, ID id, int priv) { VALUE klass = CLASS_OF(obj); + VALUE defined_class; + const ID resid = idRespond_to; + const rb_method_entry_t *const me = + method_entry_get(klass, resid, &defined_class); - if (rb_method_basic_definition_p(klass, idRespond_to)) { + if (!me) return FALSE; + if (METHOD_ENTRY_BASIC(me)) { return basic_obj_respond_to(obj, id, !priv); } else { int argc = 1; VALUE args[2]; + const rb_callable_method_entry_t *cme; + args[0] = ID2SYM(id); args[1] = Qtrue; if (priv) { - if (rb_obj_method_arity(obj, idRespond_to) != 1) { + if (rb_method_entry_arity(me) != 1) { argc = 2; } else if (!NIL_P(ruby_verbose)) { - VALUE klass = CLASS_OF(obj); - VALUE location = rb_mod_method_location(klass, idRespond_to); + VALUE location = rb_method_entry_location(me); rb_warn("%"PRIsVALUE"%c""respond_to?(:%"PRIsVALUE") is" " old fashion which takes only one parameter", (FL_TEST(klass, FL_SINGLETON) ? obj : klass), @@ -1864,7 +1870,8 @@ rb_obj_respond_to(VALUE obj, ID id, int priv) } } } - return RTEST(rb_funcall2(obj, idRespond_to, argc, args)); + cme = prepare_callable_method_entry(defined_class, resid, me); + return RTEST(vm_call0(GET_THREAD(), obj, resid, argc, args, cme)); } } |