[macruby-changes] [4485] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 31 20:45:10 PDT 2010
Revision: 4485
http://trac.macosforge.org/projects/ruby/changeset/4485
Author: lsansonetti at apple.com
Date: 2010-08-31 20:45:08 -0700 (Tue, 31 Aug 2010)
Log Message:
-----------
avoid using rb_ary_new3()
Modified Paths:
--------------
MacRuby/trunk/array.c
MacRuby/trunk/enum.c
MacRuby/trunk/error.c
MacRuby/trunk/kernel.c
MacRuby/trunk/object.c
MacRuby/trunk/string.c
Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c 2010-08-31 22:54:57 UTC (rev 4484)
+++ MacRuby/trunk/array.c 2010-09-01 03:45:08 UTC (rev 4485)
@@ -229,7 +229,8 @@
VALUE
rb_assoc_new(VALUE car, VALUE cdr)
{
- return rb_ary_new3(2, car, cdr);
+ VALUE elems[] = { car, cdr };
+ return rb_ary_new4(2, elems);
}
VALUE
@@ -891,7 +892,7 @@
if (rb_respond_to(obj, rb_intern("to_ary"))) {
return to_ary(obj);
}
- return rb_ary_new3(1, obj);
+ return rb_ary_new4(1, &obj);
}
static void
@@ -3093,7 +3094,10 @@
if (j >= i) {
j++;
}
- return rb_ary_new3(2, RARRAY_AT(ary, i), RARRAY_AT(ary, j));
+ {
+ VALUE elems[] = { RARRAY_AT(ary, i), RARRAY_AT(ary, j) };
+ return rb_ary_new4(2, elems);
+ }
case 3:
i = rb_genrand_real() * len;
@@ -3108,9 +3112,10 @@
if (k >= l && (++k >= g)) {
++k;
}
+ VALUE elems[] = { RARRAY_AT(ary, i), RARRAY_AT(ary, j),
+ RARRAY_AT(ary, k) };
+ return rb_ary_new4(3, elems);
}
- return rb_ary_new3(3, RARRAY_AT(ary, i), RARRAY_AT(ary, j),
- RARRAY_AT(ary, k));
}
if ((unsigned long)n < sizeof(idx) / sizeof(idx[0])) {
long sorted[sizeof(idx) / sizeof(idx[0])];
@@ -3277,7 +3282,8 @@
}
else if (r == 1) { /* this is a special, easy case */
for (i = 0; i < n; i++) {
- rb_yield(rb_ary_new3(1, RARRAY_AT(ary, i)));
+ VALUE elem = RARRAY_AT(ary, i);
+ rb_yield(rb_ary_new4(1, &elem));
RETURN_IF_BROKEN();
}
}
@@ -3354,7 +3360,8 @@
}
else if (n == 1) {
for (i = 0; i < len; i++) {
- rb_yield(rb_ary_new3(1, RARRAY_AT(ary, i)));
+ VALUE elem = RARRAY_AT(ary, i);
+ rb_yield(rb_ary_new4(1, &elem));
RETURN_IF_BROKEN();
}
}
Modified: MacRuby/trunk/enum.c
===================================================================
--- MacRuby/trunk/enum.c 2010-08-31 22:54:57 UTC (rev 4484)
+++ MacRuby/trunk/enum.c 2010-09-01 03:45:08 UTC (rev 4485)
@@ -619,7 +619,7 @@
group = rb_yield(i);
values = rb_hash_aref(hash, group);
if (NIL_P(values)) {
- values = rb_ary_new3(1, i);
+ values = rb_ary_new4(1, &i);
rb_hash_aset(hash, group, values);
}
else {
@@ -1080,7 +1080,8 @@
result[0] = Qundef;
if (rb_block_given_p()) {
- result[1] = rb_ary_new3(2, Qnil, Qnil);
+ VALUE elems[] = { Qnil, Qnil };
+ result[1] = rb_ary_new4(2, elems);
rb_objc_block_call(obj, selEach, 0, 0, min_ii, (VALUE)result);
}
else {
@@ -1152,7 +1153,8 @@
result[0] = Qundef;
if (rb_block_given_p()) {
- result[1] = rb_ary_new3(2, Qnil, Qnil);
+ VALUE elems[] = { Qnil, Qnil };
+ result[1] = rb_ary_new4(2, elems);
rb_objc_block_call(obj, selEach, 0, 0, max_ii, (VALUE)result);
}
else {
@@ -1235,7 +1237,8 @@
enum_minmax(VALUE obj, SEL sel)
{
VALUE result[3];
- VALUE ary = rb_ary_new3(2, Qnil, Qnil);
+ VALUE elems[] = { Qnil, Qnil };
+ VALUE ary = rb_ary_new4(2, elems);
result[0] = Qundef;
if (rb_block_given_p()) {
Modified: MacRuby/trunk/error.c
===================================================================
--- MacRuby/trunk/error.c 2010-08-31 22:54:57 UTC (rev 4484)
+++ MacRuby/trunk/error.c 2010-09-01 03:45:08 UTC (rev 4485)
@@ -527,24 +527,22 @@
VALUE
rb_check_backtrace(VALUE bt)
{
- long i;
#define BACKTRACE_ERROR "backtrace must be Array of String"
-
if (!NIL_P(bt)) {
- int t = TYPE(bt);
-
- if (t == T_STRING) return rb_ary_new3(1, bt);
+ const int t = TYPE(bt);
+ if (t == T_STRING) {
+ return rb_ary_new4(1, &bt);
+ }
if (t != T_ARRAY) {
rb_raise(rb_eTypeError, BACKTRACE_ERROR);
}
- for (i=0;i<RARRAY_LEN(bt);i++) {
+ for (int i = 0, count = RARRAY_LEN(bt); i < count; i++) {
if (TYPE(RARRAY_AT(bt, i)) != T_STRING) {
rb_raise(rb_eTypeError, BACKTRACE_ERROR);
}
}
}
#undef BACKTRACE_ERROR
-
return bt;
}
Modified: MacRuby/trunk/kernel.c
===================================================================
--- MacRuby/trunk/kernel.c 2010-08-31 22:54:57 UTC (rev 4484)
+++ MacRuby/trunk/kernel.c 2010-09-01 03:45:08 UTC (rev 4485)
@@ -187,7 +187,7 @@
VALUE ary = rb_check_convert_type(arg, T_ARRAY, "Array",
"to_a");
if (NIL_P(ary)) {
- ary = rb_ary_new3(1, arg);
+ ary = rb_ary_new4(1, &arg);
}
int count = RARRAY_LEN(ary);
if (real_argc + count >= argv_size) {
@@ -591,7 +591,7 @@
{
VALUE ary = rb_check_convert_type(splat, T_ARRAY, "Array", "to_a");
if (NIL_P(ary)) {
- ary = rb_ary_new3(1, splat);
+ ary = rb_ary_new4(1, &splat);
}
long i, count = RARRAY_LEN(ary);
for (i = 0; i < count; i++) {
@@ -883,7 +883,7 @@
{
VALUE ary = rb_check_convert_type(obj, T_ARRAY, "Array", "to_a");
if (NIL_P(ary)) {
- ary = rb_ary_new3(1, obj);
+ ary = rb_ary_new4(1, &obj);
}
return ary;
}
@@ -893,7 +893,7 @@
{
VALUE ary = rb_check_convert_type(obj, T_ARRAY, "Array", "to_ary");
if (NIL_P(ary)) {
- ary = rb_ary_new3(1, obj);
+ ary = rb_ary_new4(1, &obj);
}
return ary;
}
Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c 2010-08-31 22:54:57 UTC (rev 4484)
+++ MacRuby/trunk/object.c 2010-09-01 03:45:08 UTC (rev 4485)
@@ -2814,7 +2814,7 @@
if (NIL_P(tmp)) {
tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a");
if (NIL_P(tmp)) {
- return rb_ary_new3(1, val);
+ return rb_ary_new4(1, &val);
}
}
return tmp;
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2010-08-31 22:54:57 UTC (rev 4484)
+++ MacRuby/trunk/string.c 2010-09-01 03:45:08 UTC (rev 4485)
@@ -3112,7 +3112,7 @@
if (len == 0) {
return rb_ary_new2(0);
}
- return rb_ary_new3(1, str);
+ return rb_ary_new4(1, &str);
}
}
@@ -5596,7 +5596,10 @@
}
if (pos < 0) {
failed:
- return rb_ary_new3(3, str, rb_str_new(NULL,0), rb_str_new(NULL,0));
+ {
+ VALUE elems[] = { str, rb_str_new(NULL, 0), rb_str_new(NULL, 0) };
+ return rb_ary_new4(3, elems);
+ }
}
if (regex) {
sep = rb_str_subpat(str, sep, 0);
@@ -5606,8 +5609,9 @@
}
}
const long len = rb_str_chars_len(str);
- return rb_ary_new3(3, rstr_substr(str, 0, pos), sep,
- rstr_substr(str, pos + seplen, len - pos - seplen));
+ VALUE elems[] = { rstr_substr(str, 0, pos), sep,
+ rstr_substr(str, pos + seplen, len - pos - seplen) };
+ return rb_ary_new4(3, elems);
}
/*
@@ -5641,7 +5645,10 @@
}
if (pos < 0) {
failed:
- return rb_ary_new3(3, rb_str_new(NULL, 0), rb_str_new(NULL,0), str);
+ {
+ VALUE elems[] = { rb_str_new(NULL, 0), rb_str_new(NULL,0), str };
+ return rb_ary_new4(3, elems);
+ }
}
if (regex) {
sep = rb_reg_nth_match(0, rb_backref_get());
@@ -5650,8 +5657,9 @@
}
}
const long seplen = rb_str_chars_len(sep);
- return rb_ary_new3(3, rstr_substr(str, 0, pos), sep,
- rstr_substr(str, pos + seplen, len - pos - seplen));
+ VALUE elems[] = { rstr_substr(str, 0, pos), sep,
+ rstr_substr(str, pos + seplen, len - pos - seplen) };
+ return rb_ary_new4(3, elems);
}
/*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100831/613efd2e/attachment-0001.html>
More information about the macruby-changes
mailing list