[macruby-changes] [712] MacRuby/trunk/array.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Nov 6 13:58:01 PST 2008
Revision: 712
http://trac.macosforge.org/projects/ruby/changeset/712
Author: lsansonetti at apple.com
Date: 2008-11-06 13:58:01 -0800 (Thu, 06 Nov 2008)
Log Message:
-----------
avoid the allocation of an unnecessary object when creating the cptr version of an array
Modified Paths:
--------------
MacRuby/trunk/array.c
Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c 2008-11-06 21:55:28 UTC (rev 711)
+++ MacRuby/trunk/array.c 2008-11-06 21:58:01 UTC (rev 712)
@@ -32,34 +32,6 @@
}
}
-/* TODO optimize this */
-struct rb_objc_ary_struct {
- void *cptr;
-};
-
-/* This variable will always stay NULL, we only use its address. */
-static void *rb_objc_ary_assoc_key = NULL;
-
-static struct rb_objc_ary_struct *
-rb_objc_ary_get_struct(VALUE ary)
-{
- return rb_objc_get_associative_ref((void *)ary, &rb_objc_ary_assoc_key);
-}
-
-static struct rb_objc_ary_struct *
-rb_objc_ary_get_struct2(VALUE ary)
-{
- struct rb_objc_ary_struct *s;
-
- s = rb_objc_ary_get_struct(ary);
- if (s == NULL) {
- s = xmalloc(sizeof(struct rb_objc_ary_struct));
- rb_objc_set_associative_ref((void *)ary, &rb_objc_ary_assoc_key, s);
- s->cptr = NULL;
- }
- return s;
-}
-
static inline void
rb_ary_modify_check(VALUE ary)
{
@@ -601,6 +573,8 @@
return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)ary, offset));
}
+static void *rb_objc_ary_cptr_assoc_key = NULL;
+
const VALUE *
rb_ary_ptr(VALUE ary)
{
@@ -616,10 +590,10 @@
values = (VALUE *)xmalloc(sizeof(VALUE) * len);
CFArrayGetValues((CFArrayRef)ary, CFRangeMake(0, len),
(const void **)values);
- for (i = 0; i < len; i++)
+ for (i = 0; i < len; i++) {
values[i] = OC2RB(values[i]);
- GC_WB(&rb_objc_ary_get_struct2(ary)->cptr, values);
-
+ }
+ rb_objc_set_associative_ref((void *)ary, &rb_objc_ary_cptr_assoc_key, values);
return values;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081106/605974a3/attachment-0001.html>
More information about the macruby-changes
mailing list