[macruby-changes] [1401] MacRuby/trunk/set.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 7 22:06:28 PDT 2009


Revision: 1401
          http://trac.macosforge.org/projects/ruby/changeset/1401
Author:   ben at tanjero.com
Date:     2009-04-07 22:06:27 -0700 (Tue, 07 Apr 2009)
Log Message:
-----------
Fix up Set#merge and Set#union; fixes #241.

Modified Paths:
--------------
    MacRuby/trunk/set.c

Modified: MacRuby/trunk/set.c
===================================================================
--- MacRuby/trunk/set.c	2009-04-08 04:26:31 UTC (rev 1400)
+++ MacRuby/trunk/set.c	2009-04-08 05:06:27 UTC (rev 1401)
@@ -125,12 +125,13 @@
 }
 
 static VALUE
-rb_set_union(VALUE set, VALUE other)
+merge_i(VALUE val, VALUE *args)
 {
-    VALUE new_set = rb_set_dup(set);
-    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
@@ -138,11 +139,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, VALUE other)
+{
+    VALUE new_set = rb_set_dup(set);
+    rb_set_merge(new_set, 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/20090407/12bcba7d/attachment.html>


More information about the macruby-changes mailing list