[macruby-changes] [2332] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 15 19:04:39 PDT 2009


Revision: 2332
          http://trac.macosforge.org/projects/ruby/changeset/2332
Author:   lsansonetti at apple.com
Date:     2009-08-15 19:04:38 -0700 (Sat, 15 Aug 2009)
Log Message:
-----------
faster respond_to? primitive using the objc cache

Modified Paths:
--------------
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm_method.c

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-08-16 02:03:45 UTC (rev 2331)
+++ MacRuby/trunk/vm.cpp	2009-08-16 02:04:38 UTC (rev 2332)
@@ -2465,6 +2465,12 @@
 	else {
 	    // Method is not found...
 
+	    // Force a method resolving, because the objc cache might be
+	    // wrong.
+	    if (rb_vm_resolve_method(klass, sel)) {
+		goto recache;
+	    }
+
 	    // Does the receiver implements -forwardInvocation:?
 	    if (opt != DISPATCH_SUPER && can_forwardInvocation(self, sel)) {
 		fill_ocache(cache, self, klass, (IMP)objc_msgSend, sel, NULL,
@@ -3845,6 +3851,29 @@
 
 extern IMP basic_respond_to_imp; // vm_method.c
 
+static inline IMP
+class_respond_to(Class klass, SEL sel)
+{
+#if 0
+    Method m = class_getInstanceMethod(klass, sel);
+    if (m != NULL) {
+	return method_getImplementation(m);
+    }
+    return NULL;
+#else
+    IMP imp = class_getMethodImplementation(klass, sel);
+    if (imp == _objc_msgForward) {
+	if (rb_vm_resolve_method(klass, sel)) {
+	    imp = class_getMethodImplementation(klass, sel);
+	}
+	else {
+	    imp = NULL;
+	}
+    }
+    return imp;
+#endif
+}
+
 extern "C"
 bool
 rb_vm_respond_to(VALUE obj, SEL sel, bool priv)
@@ -3855,30 +3884,31 @@
 	    selRespondTo);
 
     if (respond_to_imp == basic_respond_to_imp) {
-	Method m = class_getInstanceMethod((Class)klass, sel);
 	bool reject_pure_ruby_methods = false;
-	if (m == NULL) {
+	IMP imp = class_respond_to((Class)klass, sel);
+	if (imp == NULL) {
 	    const char *selname = sel_getName(sel);
 	    sel = helper_sel(selname, strlen(selname));
 	    if (sel != NULL) {
-		m = class_getInstanceMethod((Class)klass, sel);
-		if (m == NULL) {
+		imp = class_respond_to((Class)klass, sel);
+		if (imp == NULL) {
 		    return false;
 		}
 		reject_pure_ruby_methods = true;
 	    }
 	}
-	IMP obj_imp = method_getImplementation(m);
-	rb_vm_method_node_t *node = obj_imp == NULL
-	    ? NULL : GET_CORE()->method_node_get(obj_imp);
+	if (imp == NULL) {
+	    return false;
+	}
 
+	rb_vm_method_node_t *node = GET_CORE()->method_node_get(imp);
 	if (node != NULL
 		&& (reject_pure_ruby_methods
 		    || (priv == 0
 			&& (rb_vm_method_node_noex(node) & NOEX_PRIVATE)))) {
 	    return false;
 	}
-        return obj_imp != NULL;
+        return true;
     }
     else {
 	VALUE args[2];

Modified: MacRuby/trunk/vm_method.c
===================================================================
--- MacRuby/trunk/vm_method.c	2009-08-16 02:03:45 UTC (rev 2331)
+++ MacRuby/trunk/vm_method.c	2009-08-16 02:04:38 UTC (rev 2332)
@@ -844,7 +844,6 @@
     rb_scan_args(argc, argv, "11", &mid, &priv);
     id = rb_to_id(mid);
     return rb_obj_respond_to(obj, id, RTEST(priv)) ? Qtrue : Qfalse;
-    return Qfalse;
 }
 
 IMP basic_respond_to_imp = NULL;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090815/04d6195a/attachment.html>


More information about the macruby-changes mailing list