summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_method_cache.rb11
-rw-r--r--vm_method.c12
2 files changed, 16 insertions, 7 deletions
diff --git a/test/ruby/test_method_cache.rb b/test/ruby/test_method_cache.rb
index a8e7e22ae3..2ed89e47bf 100644
--- a/test/ruby/test_method_cache.rb
+++ b/test/ruby/test_method_cache.rb
@@ -61,5 +61,16 @@ class TestMethodCache < Test::Unit::TestCase
assert_equal :c2, c3.new.foo
end
+
+ def test_negative_cache_with_and_without_subclasses
+ c0 = Class.new{}
+ c1 = Class.new(c0){}
+ c0.new.foo rescue nil
+ c1.new.foo rescue nil
+ c1.module_eval{ def foo = :c1 }
+ c0.module_eval{ def foo = :c0 }
+
+ assert_equal :c0, c0.new.foo
+ end
end
diff --git a/vm_method.c b/vm_method.c
index a3bebae95d..2573e708ba 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -129,17 +129,15 @@ rb_clear_constant_cache(void)
}
static void
-invalidate_negative_cache(ID mid, bool invalidate_cme)
+invalidate_negative_cache(ID mid)
{
const rb_callable_method_entry_t *cme;
rb_vm_t *vm = GET_VM();
if (rb_id_table_lookup(vm->negative_cme_table, mid, (VALUE *)&cme)) {
rb_id_table_delete(vm->negative_cme_table, mid);
- if (invalidate_cme) {
- vm_cme_invalidate((rb_callable_method_entry_t *)cme);
- RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
- }
+ vm_cme_invalidate((rb_callable_method_entry_t *)cme);
+ RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
}
}
@@ -162,7 +160,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid)
// invalidate CCs
if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, (VALUE *)&ccs)) {
- if (NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid, false);
+ if (NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid);
rb_vm_ccs_free(ccs);
rb_id_table_delete(cc_tbl, mid);
RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs);
@@ -211,7 +209,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid)
RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
}
else {
- invalidate_negative_cache(mid, true);
+ invalidate_negative_cache(mid);
}
}
}