From 421314cf4e532cd4b840924b73f73fe33f25647b Mon Sep 17 00:00:00 2001 From: shugo Date: Thu, 29 Nov 2012 12:50:10 +0000 Subject: * vm_method.c (rb_method_entry_make): add a method entry with VM_METHOD_TYPE_REFINED to the class refined by the refinement if the target module is a refinement. When a method entry with VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with the same name is searched in refinements. If such a method is found, the method is invoked. Otherwise, the original method in the refined class (rb_method_definition_t::body.orig_def) is invoked. This change is made to simplify the normal method lookup and to improve the performance of normal method calls. * vm_method.c (EXPR1, search_method, rb_method_entry), vm_eval.c (rb_call0, rb_search_method_entry): do not use refinements for method lookup. * vm_insnhelper.c (vm_call_method): search methods in refinements if ci->me is VM_METHOD_TYPE_REFINED. If the method is called by super (i.e., ci->call == vm_call_super_method), skip the same method entry as the current method to avoid infinite call of the same method. * class.c (include_modules_at): add a refined method entry for each method defined in a module included in a refinement. * class.c (rb_prepend_module): set an empty table to RCLASS_M_TBL(klass) to add refined method entries, because refinements should have priority over prepended modules. * proc.c (mnew): use rb_method_entry_with_refinements() to get a refined method. * test/ruby/test_refinement.rb (test_inline_method_cache): do not skip the test because it should pass successfully. * test/ruby/test_refinement.rb (test_redefine_refined_method): new test for the case a refined method is redefined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- method.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'method.h') diff --git a/method.h b/method.h index a87fc5c1ba..57a409f8a9 100644 --- a/method.h +++ b/method.h @@ -42,7 +42,8 @@ typedef enum { VM_METHOD_TYPE_NOTIMPLEMENTED, VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */ VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */ - VM_METHOD_TYPE_CFUNC_FRAMELESS + VM_METHOD_TYPE_CFUNC_FRAMELESS, + VM_METHOD_TYPE_REFINED, } rb_method_type_t; struct rb_call_info_struct; @@ -72,6 +73,7 @@ typedef struct rb_method_definition_struct { OPTIMIZED_METHOD_TYPE_SEND, OPTIMIZED_METHOD_TYPE_CALL } optimize_type; + struct rb_method_definition_struct *orig_def; } body; int alias_count; } rb_method_definition_t; @@ -94,9 +96,16 @@ struct unlinked_method_entry_list_entry { void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex); rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex); rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr); - -rb_method_entry_t *rb_method_entry_get_with_refinements(VALUE refinements, VALUE klass, ID id, VALUE *define_class_ptr); -rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, VALUE refinements, ID id, VALUE *define_class_ptr); +void rb_add_refined_method_entry(VALUE refined_class, ID mid); +rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, + rb_method_entry_t *me, + rb_method_entry_t *me_buf, + VALUE *defined_class_ptr); +rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id, + rb_method_entry_t *me_buf, + VALUE *defined_class_ptr); + +rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr); rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex); int rb_method_entry_arity(const rb_method_entry_t *me); -- cgit v1.2.3