[macruby-changes] [451] MacRuby/branches/lrz_unstable

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 18 13:32:29 PDT 2008


Revision: 451
          http://trac.macosforge.org/projects/ruby/changeset/451
Author:   lsansonetti at apple.com
Date:     2008-08-18 13:32:29 -0700 (Mon, 18 Aug 2008)
Log Message:
-----------
some perf work

Modified Paths:
--------------
    MacRuby/branches/lrz_unstable/array.c
    MacRuby/branches/lrz_unstable/numeric.c
    MacRuby/branches/lrz_unstable/objc.m

Modified: MacRuby/branches/lrz_unstable/array.c
===================================================================
--- MacRuby/branches/lrz_unstable/array.c	2008-08-18 20:31:02 UTC (rev 450)
+++ MacRuby/branches/lrz_unstable/array.c	2008-08-18 20:32:29 UTC (rev 451)
@@ -305,8 +305,13 @@
     }
     else {
 	long i;
+	const void **values = alloca(sizeof(void *) * len);
+	void *ocval = RB2OC(val);
+
 	for (i=0; i<len; i++)
-	    rb_ary_insert(ary, i, val);
+	    values[i] = ocval;
+
+	CFArrayReplaceValues((CFMutableArrayRef)ary, CFRangeMake(0, 0), values, len); 
     }
     return ary;
 }

Modified: MacRuby/branches/lrz_unstable/numeric.c
===================================================================
--- MacRuby/branches/lrz_unstable/numeric.c	2008-08-18 20:31:02 UTC (rev 450)
+++ MacRuby/branches/lrz_unstable/numeric.c	2008-08-18 20:32:29 UTC (rev 451)
@@ -94,22 +94,38 @@
 VALUE rb_eFloatDomainError;
 
 #if WITH_OBJC
-static CFMutableDictionaryRef fixnum_cache = NULL;
+static CFMutableDictionaryRef fixnum_dict = NULL;
+static struct RFixnum *fixnum_cache = NULL;
 
 VALUE
 rb_box_fixnum(VALUE fixnum)
 {
     struct RFixnum *val;
+    long value;
 
-    if (fixnum_cache == NULL)
-	fixnum_cache = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); 
- 
-    val = (struct RFixnum *)CFDictionaryGetValue(fixnum_cache, (const void *)fixnum);
+    if (fixnum_dict == NULL)
+	fixnum_dict = CFDictionaryCreateMutable(kCFAllocatorMalloc, 0, NULL, NULL); 
+
+    value = FIX2LONG(fixnum);
+
+    if (value >= 0 && value <= 1000000) {
+	if (fixnum_cache == NULL) {
+	   fixnum_cache = (struct RFixnum *)calloc(1, sizeof(struct RFixnum) * 1000000);
+	}
+	val = &fixnum_cache[value];
+	if (val->klass == 0) {
+	    val->klass = rb_cFixnum;
+	    val->value = value;
+	}
+	return (VALUE)val;
+    }
+
+    val = (struct RFixnum *)CFDictionaryGetValue(fixnum_dict, (const void *)fixnum);
     if (val == NULL) {
 	val = (struct RFixnum *)malloc(sizeof(struct RFixnum));
 	val->klass = rb_cFixnum;
 	val->value = FIX2LONG(fixnum);
-	CFDictionarySetValue(fixnum_cache, (const void *)fixnum, (const void *)val);
+	CFDictionarySetValue(fixnum_dict, (const void *)fixnum, (const void *)val);
     }
 
     return (VALUE)val;

Modified: MacRuby/branches/lrz_unstable/objc.m
===================================================================
--- MacRuby/branches/lrz_unstable/objc.m	2008-08-18 20:31:02 UTC (rev 450)
+++ MacRuby/branches/lrz_unstable/objc.m	2008-08-18 20:32:29 UTC (rev 451)
@@ -2079,10 +2079,12 @@
 bs_parse_cb(const char *path, bs_element_type_t type, void *value, void *ctx)
 {
     bool do_not_free = false;
-    CFMutableDictionaryRef rb_cObject_dict;
+    static CFMutableDictionaryRef rb_cObject_dict = NULL;
 
-    rb_cObject_dict = rb_class_ivar_dict(rb_cObject);
-    assert(rb_cObject_dict != NULL);
+    if (rb_cObject_dict == NULL) {
+	rb_cObject_dict = rb_class_ivar_dict(rb_cObject);
+	assert(rb_cObject_dict != NULL);
+    }
 
     switch (type) {
 	case BS_ELEMENT_ENUM:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080818/8c926eb0/attachment.html 


More information about the macruby-changes mailing list