[macruby-changes] [1994] MacRuby/branches/experimental/variable.c

source_changes at macosforge.org source_changes at macosforge.org
Sun Jul 5 16:17:30 PDT 2009


Revision: 1994
          http://trac.macosforge.org/projects/ruby/changeset/1994
Author:   lsansonetti at apple.com
Date:     2009-07-05 16:17:30 -0700 (Sun, 05 Jul 2009)
Log Message:
-----------
try the ivar slot logic for any object type

Modified Paths:
--------------
    MacRuby/branches/experimental/variable.c

Modified: MacRuby/branches/experimental/variable.c
===================================================================
--- MacRuby/branches/experimental/variable.c	2009-07-05 23:16:58 UTC (rev 1993)
+++ MacRuby/branches/experimental/variable.c	2009-07-05 23:17:30 UTC (rev 1994)
@@ -1018,23 +1018,22 @@
 {
     VALUE val;
 
+    const int slot = rb_vm_find_class_ivar_slot(CLASS_OF(obj), id);
+    if (slot != -1) {
+	return rb_vm_get_ivar_from_slot(obj, slot);
+    }
+
     switch (TYPE(obj)) {
 	case T_OBJECT:
 	    {
 		val = Qundef;
 
-		int slot = rb_vm_find_class_ivar_slot(CLASS_OF(obj), id);
-		if (slot != -1) {
-		    val = rb_vm_get_ivar_from_slot(obj, slot);
-		}
-		else {
-		    if (ROBJECT(obj)->tbl != NULL) {
-			if (!CFDictionaryGetValueIfPresent(
-				    (CFDictionaryRef)ROBJECT(obj)->tbl,
-				    (const void *)id,
-				    (const void **)&val)) {
-			    val = Qundef;
-			}
+		if (ROBJECT(obj)->tbl != NULL) {
+		    if (!CFDictionaryGetValueIfPresent(
+				(CFDictionaryRef)ROBJECT(obj)->tbl,
+				(const void *)id,
+				(const void **)&val)) {
+			val = Qundef;
 		    }
 		}
 
@@ -1092,27 +1091,28 @@
     if (OBJ_FROZEN(obj)) {
 	rb_error_frozen("object");
     }
+
+    const int slot = rb_vm_find_class_ivar_slot(CLASS_OF(obj), id);
+    if (slot != -1) {
+	rb_vm_set_ivar_from_slot(obj, val, slot);
+	return val;
+    }
+
     switch (TYPE(obj)) {
 	case T_OBJECT:
 	    {
-		int slot = rb_vm_find_class_ivar_slot(CLASS_OF(obj), id);
-		if (slot != -1) {
-		    rb_vm_set_ivar_from_slot(obj, val, slot);
-		}
-		else {
-		    if (ROBJECT(obj)->tbl == NULL) {
-			CFMutableDictionaryRef tbl;
+		if (ROBJECT(obj)->tbl == NULL) {
+		    CFMutableDictionaryRef tbl;
 
-			tbl = CFDictionaryCreateMutable(NULL, 0, NULL, 
-				&rb_cfdictionary_value_cb);
+		    tbl = CFDictionaryCreateMutable(NULL, 0, NULL, 
+			    &rb_cfdictionary_value_cb);
 
-			GC_WB(&ROBJECT(obj)->tbl, tbl);
-			CFMakeCollectable(tbl);
-		    }
+		    GC_WB(&ROBJECT(obj)->tbl, tbl);
+		    CFMakeCollectable(tbl);
+		}
 
-		    CFDictionarySetValue(ROBJECT(obj)->tbl, 
-			    (const void *)id, (const void *)val);
-		}
+		CFDictionarySetValue(ROBJECT(obj)->tbl, 
+			(const void *)id, (const void *)val);
 	    }
 	    break;
 
@@ -1142,22 +1142,23 @@
 {
     VALUE val;
 
+    const int slot = rb_vm_find_class_ivar_slot(CLASS_OF(obj), id);
+    if (slot != -1) {
+	if (rb_vm_get_ivar_from_slot(obj, slot) != Qundef) {
+	    return Qtrue;
+	}
+    }
+
     switch (TYPE(obj)) {
 	case T_OBJECT:
 	    {
 		val = Qundef;
 
-		int slot = rb_vm_find_class_ivar_slot(CLASS_OF(obj), id);
-		if (slot != -1) {
-		    val = rb_vm_get_ivar_from_slot(obj, slot);
-		}
-		else {
-		    if (ROBJECT(obj)->tbl != NULL) {
-			if (CFDictionaryGetValueIfPresent(
-				    (CFDictionaryRef)ROBJECT(obj)->tbl,
-				    (const void *)id, NULL)) {
-			    val = Qtrue;
-			}
+		if (ROBJECT(obj)->tbl != NULL) {
+		    if (CFDictionaryGetValueIfPresent(
+				(CFDictionaryRef)ROBJECT(obj)->tbl,
+				(const void *)id, NULL)) {
+			val = Qtrue;
 		    }
 		}
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090705/e833c0d9/attachment-0001.html>


More information about the macruby-changes mailing list