[macruby-changes] [3531] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 15 14:47:13 PST 2010
Revision: 3531
http://trac.macosforge.org/projects/ruby/changeset/3531
Author: lsansonetti at apple.com
Date: 2010-02-15 14:47:12 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
Array#join: convert separator as string, Array#<=>: return nil if given obj is not array, Array#dup/#clone: appropriately handle singleton classes, fixed misc bugs in eql
Modified Paths:
--------------
MacRuby/trunk/NSArray.m
MacRuby/trunk/array.c
Modified: MacRuby/trunk/NSArray.m
===================================================================
--- MacRuby/trunk/NSArray.m 2010-02-15 22:44:42 UTC (rev 3530)
+++ MacRuby/trunk/NSArray.m 2010-02-15 22:47:12 UTC (rev 3531)
@@ -1225,6 +1225,10 @@
return rb_str_new(0, 0);
}
+ if (!NIL_P(sep)) {
+ StringValue(sep);
+ }
+
bool taint = false;
if (OBJ_TAINTED(ary) || OBJ_TAINTED(sep)) {
taint = true;
@@ -1237,31 +1241,29 @@
VALUE result = rb_str_new(0, 0);
for (long i = 0, count = RARRAY_LEN(ary); i < count; i++) {
- VALUE tmp = RARRAY_AT(ary, i);
- switch (TYPE(tmp)) {
+ VALUE elem = RARRAY_AT(ary, i);
+ switch (TYPE(elem)) {
case T_STRING:
break;
case T_ARRAY:
{
- VALUE args[2];
-
- args[0] = tmp;
- args[1] = sep;
- tmp = rb_exec_recursive(recursive_join, ary, (VALUE)args);
+ VALUE args[2] = {elem, sep};
+ elem = rb_exec_recursive(recursive_join, ary, (VALUE)args);
}
break;
default:
- tmp = rb_obj_as_string(tmp);
+ elem = rb_obj_as_string(elem);
+ break;
}
if (i > 0 && !NIL_P(sep)) {
rb_str_buf_append(result, sep);
}
- rb_str_buf_append(result, tmp);
+ rb_str_buf_append(result, elem);
- if (OBJ_TAINTED(tmp)) {
+ if (OBJ_TAINTED(elem)) {
taint = true;
}
- if (OBJ_UNTRUSTED(tmp)) {
+ if (OBJ_UNTRUSTED(elem)) {
untrust = true;
}
}
Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c 2010-02-15 22:44:42 UTC (rev 3530)
+++ MacRuby/trunk/array.c 2010-02-15 22:47:12 UTC (rev 3531)
@@ -156,9 +156,6 @@
if (x == y) {
return Qtrue;
}
- if (SPECIAL_CONST_P(x) && SPECIAL_CONST_P(y) && TYPE(x) == TYPE(y)) {
- return Qfalse;
- }
if (SYMBOL_P(x)) {
return x == y ? Qtrue : Qfalse;
}
@@ -827,7 +824,7 @@
assert(origin < RARY(ary)->len);
for (size_t i = origin; i < RARY(ary)->len; i++) {
VALUE item2 = rary_elt(ary, i);
- if (rb_equal_fast(item, item2) == Qtrue) {
+ if (rb_equal_fast(item2, item) == Qtrue) {
return i;
}
}
@@ -1189,12 +1186,25 @@
return RARY(ary)->len == 0 ? Qtrue : Qfalse;
}
+static VALUE
+rary_copy(VALUE rcv, VALUE klass)
+{
+ VALUE dup = rary_alloc(klass, 0);
+ rary_concat(dup, rcv, 0, RARY(rcv)->len);
+ return dup;
+}
+
VALUE
rary_dup(VALUE ary, SEL sel)
{
- VALUE dup = rary_alloc(rb_cRubyArray, 0);
- rary_concat(dup, ary, 0, RARY(ary)->len);
- *(VALUE *)dup = *(VALUE *)ary;
+ VALUE klass = CLASS_OF(ary);
+ while (RCLASS_SINGLETON(klass)) {
+ klass = RCLASS_SUPER(klass);
+ }
+ assert(rb_klass_is_rary(klass));
+
+ VALUE dup = rary_copy(ary, klass);
+
if (OBJ_TAINTED(ary)) {
OBJ_TAINT(dup);
}
@@ -1207,7 +1217,14 @@
static VALUE
rary_clone(VALUE ary, SEL sel)
{
- VALUE clone = rary_dup(ary, 0);
+ VALUE clone = rary_copy(ary, CLASS_OF(ary));
+
+ if (OBJ_TAINTED(ary)) {
+ OBJ_TAINT(clone);
+ }
+ if (OBJ_UNTRUSTED(ary)) {
+ OBJ_UNTRUST(clone);
+ }
if (OBJ_FROZEN(ary)) {
OBJ_FREEZE(clone);
}
@@ -2356,7 +2373,10 @@
VALUE
rary_cmp(VALUE ary1, SEL sel, VALUE ary2)
{
- ary2 = to_ary(ary2);
+ ary2 = rb_check_array_type(ary2);
+ if (NIL_P(ary2)) {
+ return Qnil;
+ }
if (ary1 == ary2) {
return INT2FIX(0);
}
@@ -2505,6 +2525,7 @@
for (size_t i = 0; i < n; i++) {
VALUE item = rary_elt(ary, i);
size_t pos = i + 1;
+
while (pos < n && (pos = rary_index_of_item(ary, pos, item))
!= NOT_FOUND) {
rary_erase(ary, pos, 1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/756180d5/attachment-0001.html>
More information about the macruby-changes
mailing list