[macruby-changes] [290] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Jun 15 01:42:23 PDT 2008


Revision: 290
          http://trac.macosforge.org/projects/ruby/changeset/290
Author:   lsansonetti at apple.com
Date:     2008-06-15 01:42:22 -0700 (Sun, 15 Jun 2008)

Log Message:
-----------
another objc dispatcher boost by caching the BS method descriptions

Modified Paths:
--------------
    MacRuby/trunk/objc.m
    MacRuby/trunk/vm_insnhelper.c

Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m	2008-06-15 05:21:42 UTC (rev 289)
+++ MacRuby/trunk/objc.m	2008-06-15 08:42:22 UTC (rev 290)
@@ -1055,6 +1055,8 @@
     return type;
 }
 
+extern NODE *rb_current_cfunc_node;
+
 static VALUE
 rb_objc_to_ruby_closure(int argc, VALUE *argv, VALUE rcv)
 {
@@ -1071,16 +1073,35 @@
     void *imp;
     bs_element_method_t *bs_method;
 
-    selector = sel_registerName(rb_id2name(rb_frame_this_func()));
-    method = class_getInstanceMethod(object_getClass((void *)rcv), selector); 
+    rb_objc_rval_to_ocid(rcv, (void **)&ocrcv);
+    klass = *(Class *)ocrcv;
+
+    assert(rb_current_cfunc_node != NULL);
+
+    if (rb_current_cfunc_node->u3.value == 0) {
+	selector = sel_registerName(rb_id2name(rb_frame_this_func()));
+	bs_method = rb_bs_find_method(klass, selector);
+	if (bs_method != NULL)
+	    rb_current_cfunc_node->u3.value = (VALUE)bs_method;
+	else
+	    rb_current_cfunc_node->u3.value = Qnil;
+    }
+    else {
+	if (rb_current_cfunc_node->u3.value == Qnil) {
+	    bs_method = NULL;
+	    selector = sel_registerName(rb_id2name(rb_frame_this_func()));
+	}
+	else {
+	    bs_method = (bs_element_method_t *)rb_current_cfunc_node->u3.value;
+	    selector = bs_method->name;
+	}
+    }
+
+    method = class_getInstanceMethod(klass, selector); 
     assert(method != NULL);
     count = method_getNumberOfArguments(method);
     assert(count >= 2);
 
-    rb_objc_rval_to_ocid(rcv, (void **)&ocrcv);
-    klass = *(Class *)ocrcv;
-
-    bs_method = rb_bs_find_method(klass, selector);
     real_count = count;
     if (bs_method != NULL && bs_method->variadic) {
 	if (argc < count - 2)

Modified: MacRuby/trunk/vm_insnhelper.c
===================================================================
--- MacRuby/trunk/vm_insnhelper.c	2008-06-15 05:21:42 UTC (rev 289)
+++ MacRuby/trunk/vm_insnhelper.c	2008-06-15 08:42:22 UTC (rev 290)
@@ -353,6 +353,10 @@
     return Qnil;		/* not reached */
 }
 
+#if WITH_OBJC
+NODE *rb_current_cfunc_node = NULL;
+#endif
+
 static inline VALUE
 vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp,
 	      int num, ID id, VALUE recv, VALUE klass,
@@ -371,7 +375,13 @@
 
 	reg_cfp->sp -= num + 1;
 
+#if WITH_OBJC
+	rb_current_cfunc_node = (NODE *)mn;
+#endif
 	val = call_cfunc(mn->nd_cfnc, recv, mn->nd_argc, num, reg_cfp->sp + 1);
+#if WITH_OBJC
+	rb_current_cfunc_node = NULL;
+#endif
 
 	if (reg_cfp != th->cfp + 1) {
 	    rb_bug("cfp consistency error - send");

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080615/7c07b95f/attachment.htm 


More information about the macruby-changes mailing list