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

ruby-changes:25053

From: shugo <ko1@a...>
Date: Sat, 6 Oct 2012 16:32:59 +0900 (JST)
Subject: [ruby-changes:25053] shugo:r37105 (trunk): * vm_method.c (search_method): check omod only once for performance.

shugo	2012-10-06 16:32:45 +0900 (Sat, 06 Oct 2012)

  New Revision: 37105

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

  Log:
    * vm_method.c (search_method): check omod only once for performance.

  Modified files:
    trunk/ChangeLog
    trunk/vm_method.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37104)
+++ ChangeLog	(revision 37105)
@@ -1,3 +1,7 @@
+Sat Oct  6 16:32:04 2012  Shugo Maeda  <shugo@r...>
+
+	* vm_method.c (search_method): check omod only once for performance.
+
 Sat Oct  6 09:42:04 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* enc/encdb.c, enc/utf_16_32.h (ENC_DUMMY_UNICODE): endian-less wide
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 37104)
+++ vm_method.c	(revision 37105)
@@ -394,16 +394,24 @@
     return result;
 }
 
-static rb_method_entry_t*
-search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
+static inline int
+lookup_method_table(VALUE klass, ID id, st_data_t *body)
 {
+    st_table *m_tbl = RCLASS_M_TBL(klass);
+    if (!m_tbl) {
+	m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(RBASIC(klass)->klass));
+    }
+    return st_lookup(m_tbl, id, body);
+}
+
+static inline rb_method_entry_t*
+search_method_with_omod(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
+{
     st_data_t body;
     VALUE iclass, skipped_class = Qnil;
 
     for (body = 0; klass; klass = RCLASS_SUPER(klass)) {
-	st_table *m_tbl;
-
-	if (!NIL_P(omod) && klass != skipped_class) {
+	if (klass != skipped_class) {
 	    iclass = rb_hash_lookup(omod, klass);
 	    if (NIL_P(iclass) && BUILTIN_TYPE(klass) == T_ICLASS) {
 		iclass = rb_hash_lookup(omod, RBASIC(klass)->klass);
@@ -415,11 +423,7 @@
 		klass = iclass;
 	    }
 	}
-	m_tbl = RCLASS_M_TBL(klass);
-	if (!m_tbl) {
-	    m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(RBASIC(klass)->klass));
-	}
-	if (st_lookup(m_tbl, id, &body)) break;
+	if (lookup_method_table(klass, id, &body)) break;
     }
 
     if (defined_class_ptr)
@@ -427,6 +431,31 @@
     return (rb_method_entry_t *)body;
 }
 
+static inline rb_method_entry_t*
+search_method_without_omod(VALUE klass, ID id, VALUE *defined_class_ptr)
+{
+    st_data_t body;
+
+    for (body = 0; klass; klass = RCLASS_SUPER(klass)) {
+	if (lookup_method_table(klass, id, &body)) break;
+    }
+
+    if (defined_class_ptr)
+	*defined_class_ptr = klass;
+    return (rb_method_entry_t *)body;
+}
+
+static rb_method_entry_t*
+search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
+{
+    if (NIL_P(omod)) {
+	return search_method_without_omod(klass, id, defined_class_ptr);
+    }
+    else {
+	return search_method_with_omod(klass, id, omod, defined_class_ptr);
+    }
+}
+
 /*
  * search method entry without the method cache.
  *

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

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