[前][次][番号順一覧][スレッド一覧]

ruby-changes:39564

From: nobu <ko1@a...>
Date: Thu, 20 Aug 2015 08:53:36 +0900 (JST)
Subject: [ruby-changes:39564] nobu:r51645 (trunk): vm_method.c: reuse method entry

nobu	2015-08-20 08:53:12 +0900 (Thu, 20 Aug 2015)

  New Revision: 51645

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51645

  Log:
    vm_method.c: reuse method entry
    
    * vm_method.c (rb_obj_respond_to): reuse found method entry
      instead of searching same entry repeatedly.

  Modified files:
    trunk/ChangeLog
    trunk/method.h
    trunk/proc.c
    trunk/vm_method.c
Index: method.h
===================================================================
--- method.h	(revision 51644)
+++ method.h	(revision 51645)
@@ -197,6 +197,7 @@ int rb_method_entry_arity(const rb_metho https://github.com/ruby/ruby/blob/trunk/method.h#L197
 int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
 st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
 
+VALUE rb_method_entry_location(const rb_method_entry_t *me);
 VALUE rb_mod_method_location(VALUE mod, ID id);
 VALUE rb_obj_method_location(VALUE obj, ID id);
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51644)
+++ ChangeLog	(revision 51645)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Aug 20 08:53:09 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_method.c (rb_obj_respond_to): reuse found method entry
+	  instead of searching same entry repeatedly.
+
 Thu Aug 20 08:31:17 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (replace_real_basename), win32/win32.c (opendir_internal):
Index: proc.c
===================================================================
--- proc.c	(revision 51644)
+++ proc.c	(revision 51645)
@@ -2249,8 +2249,8 @@ method_def_location(const rb_method_defi https://github.com/ruby/ruby/blob/trunk/proc.c#L2249
     return iseq_location(method_def_iseq(def));
 }
 
-static VALUE
-method_entry_location(const rb_method_entry_t *me)
+VALUE
+rb_method_entry_location(const rb_method_entry_t *me)
 {
     if (!me) return Qnil;
     return method_def_location(me->def);
@@ -2260,7 +2260,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L2260
 rb_mod_method_location(VALUE mod, ID id)
 {
     const rb_method_entry_t *me = original_method_entry(mod, id);
-    return method_entry_location(me);
+    return rb_method_entry_location(me);
 }
 
 VALUE
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 51644)
+++ vm_method.c	(revision 51645)
@@ -1833,22 +1833,28 @@ int https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1833
 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 https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1870
 		}
 	    }
 	}
-	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));
     }
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]