[macruby-changes] [1408] MacRuby/branches/experimental/set.c
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 10 21:36:13 PDT 2009
Revision: 1408
http://trac.macosforge.org/projects/ruby/changeset/1408
Author: lsansonetti at apple.com
Date: 2009-04-10 21:36:13 -0700 (Fri, 10 Apr 2009)
Log Message:
-----------
merged r1401 from trunk
Modified Paths:
--------------
MacRuby/branches/experimental/set.c
Modified: MacRuby/branches/experimental/set.c
===================================================================
--- MacRuby/branches/experimental/set.c 2009-04-11 04:19:05 UTC (rev 1407)
+++ MacRuby/branches/experimental/set.c 2009-04-11 04:36:13 UTC (rev 1408)
@@ -128,12 +128,14 @@
}
static VALUE
-rb_set_union(VALUE set, SEL sel, VALUE other)
+merge_i(VALUE val, VALUE *args)
{
- VALUE new_set = rb_set_dup(set, 0);
- CFSetApplyFunction((CFMutableSetRef)other, rb_set_union_callback, (void *)new_set);
+ VALUE set = (VALUE)args;
+ if (!CFSetContainsValue((CFMutableSetRef)set, (const void *)RB2OC(val))) {
+ CFSetAddValue((CFMutableSetRef)set, (const void *)RB2OC(val));
+ }
- return new_set;
+ return Qnil;
}
static VALUE
@@ -141,11 +143,24 @@
{
rb_set_modify_check(set);
- CFSetApplyFunction((CFMutableSetRef)other, rb_set_union_callback, (void *)set);
+ VALUE klass = *(VALUE *)other;
+ if (klass == rb_cCFSet || klass == rb_cNSSet || klass == rb_cNSMutableSet)
+ CFSetApplyFunction((CFMutableSetRef)other, rb_set_union_callback, (void *)set);
+ else
+ rb_block_call(other, rb_intern("each"), 0, 0, merge_i, (VALUE)set);
return set;
}
+static VALUE
+rb_set_union(VALUE set, SEL sel, VALUE other)
+{
+ VALUE new_set = rb_set_dup(set, 0);
+ rb_set_merge(new_set, 0, other);
+
+ return new_set;
+}
+
static void
rb_set_subtract_callback(const void *value, void *context)
{
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090410/cf75e567/attachment.html>
More information about the macruby-changes
mailing list