about summary refs log tree commit homepage
path: root/vm_method.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/vm_method.c b/vm_method.c
index 8723a51acf..85b4b936f3 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -2,6 +2,7 @@
  * This file is included by vm.c
  */
 
+#if OPT_GLOBAL_METHOD_CACHE
 #ifndef GLOBAL_METHOD_CACHE_SIZE
 #define GLOBAL_METHOD_CACHE_SIZE 0x800
 #endif
@@ -16,6 +17,9 @@
 
 #define GLOBAL_METHOD_CACHE_KEY(c,m) ((((c)>>3)^(m))&GLOBAL_METHOD_CACHE_MASK)
 #define GLOBAL_METHOD_CACHE(c,m) (global_method_cache + GLOBAL_METHOD_CACHE_KEY(c,m))
+#else
+#define GLOBAL_METHOD_CACHE(c,m) (NULL)
+#endif
 #include "method.h"
 
 #define NOEX_NOREDEF 0
@@ -42,7 +46,10 @@ struct cache_entry {
     VALUE defined_class;
 };
 
+#if OPT_GLOBAL_METHOD_CACHE
 static struct cache_entry global_method_cache[GLOBAL_METHOD_CACHE_SIZE];
+#endif
+
 #define ruby_running (GET_VM()->running)
 /* int ruby_running = 0; */
 
@@ -574,19 +581,24 @@ rb_method_entry_get_without_cache(VALUE klass, ID id,
         defined_class = me->klass;
 
     if (ruby_running) {
-        struct cache_entry *ent;
-        ent = GLOBAL_METHOD_CACHE(klass, id);
-        ent->class_serial = RCLASS_SERIAL(klass);
-        ent->method_state = GET_GLOBAL_METHOD_STATE();
-        ent->defined_class = defined_class;
-        ent->mid = id;
+        if (OPT_GLOBAL_METHOD_CACHE) {
+            struct cache_entry *ent;
+            ent = GLOBAL_METHOD_CACHE(klass, id);
+            ent->class_serial = RCLASS_SERIAL(klass);
+            ent->method_state = GET_GLOBAL_METHOD_STATE();
+            ent->defined_class = defined_class;
+            ent->mid = id;
 
-        if (UNDEFINED_METHOD_ENTRY_P(me)) {
-            ent->me = 0;
-            me = 0;
+            if (UNDEFINED_METHOD_ENTRY_P(me)) {
+                ent->me = 0;
+                me = 0;
+            }
+            else {
+                ent->me = me;
+            }
         }
-        else {
-            ent->me = me;
+        else if (UNDEFINED_METHOD_ENTRY_P(me)) {
+            me = 0;
         }
     }
 
@@ -595,10 +607,10 @@ rb_method_entry_get_without_cache(VALUE klass, ID id,
     return me;
 }
 
-#if VM_DEBUG_VERIFY_METHOD_CACHE
 static void
 verify_method_cache(VALUE klass, ID id, VALUE defined_class, rb_method_entry_t *me)
 {
+#if VM_DEBUG_VERIFY_METHOD_CACHE
     VALUE actual_defined_class;
     rb_method_entry_t *actual_me =
         rb_method_entry_get_without_cache(klass, id, &actual_defined_class);
@@ -606,26 +618,24 @@ verify_method_cache(VALUE klass, ID id, VALUE defined_class, rb_method_entry_t *
     if (me != actual_me || defined_class != actual_defined_class) {
         rb_bug("method cache verification failed");
     }
-}
 #endif
+}
 
 rb_method_entry_t *
 rb_method_entry(VALUE klass, ID id, VALUE *defined_class_ptr)
 {
-#if OPT_GLOBAL_METHOD_CACHE
-    struct cache_entry *ent;
-    ent = GLOBAL_METHOD_CACHE(klass, id);
-    if (ent->method_state == GET_GLOBAL_METHOD_STATE() &&
-        ent->class_serial == RCLASS_SERIAL(klass) &&
-        ent->mid == id) {
-        if (defined_class_ptr)
-            *defined_class_ptr = ent->defined_class;
-#if VM_DEBUG_VERIFY_METHOD_CACHE
-        verify_method_cache(klass, id, ent->defined_class, ent->me);
-#endif
-        return ent->me;
+    if (OPT_GLOBAL_METHOD_CACHE) {
+        struct cache_entry *ent;
+        ent = GLOBAL_METHOD_CACHE(klass, id);
+        if (ent->method_state == GET_GLOBAL_METHOD_STATE() &&
+            ent->class_serial == RCLASS_SERIAL(klass) &&
+            ent->mid == id) {
+            if (defined_class_ptr)
+                *defined_class_ptr = ent->defined_class;
+            verify_method_cache(klass, id, ent->defined_class, ent->me);
+            return ent->me;
+        }
     }
-#endif
 
     return rb_method_entry_get_without_cache(klass, id, defined_class_ptr);
 }