From c29c44c4544896cf3e9d0788f52597e1f73dce02 Mon Sep 17 00:00:00 2001 From: shugo Date: Sat, 6 Oct 2012 07:32:45 +0000 Subject: [PATCH] * vm_method.c (search_method): check omod only once for performance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ vm_method.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e36a29387..95e720dce1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Oct 6 16:32:04 2012 Shugo Maeda + + * vm_method.c (search_method): check omod only once for performance. + Sat Oct 6 09:42:04 2012 Nobuyoshi Nakada * enc/encdb.c, enc/utf_16_32.h (ENC_DUMMY_UNICODE): endian-less wide diff --git a/vm_method.c b/vm_method.c index e44782ce6d..c5b33caa58 100644 --- a/vm_method.c +++ b/vm_method.c @@ -394,16 +394,24 @@ copy_refinement_iclass(VALUE iclass, VALUE superclass) 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 @@ search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr) 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 @@ search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr) 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. *