summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-19 15:45:46 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-19 15:45:46 +0000
commit7e35911e105409fabe48dc2a6214479b6a6ffa24 (patch)
tree5b28440687c1701389b14598454e99aee9a925ba /enum.c
parente08bc0a22ae6c2d2ac0664d82675ca81a30df607 (diff)
* ext/pty/pty.c (pty_finalize_syswait): join (using Thread#value)
before detach pid. [ruby-talk:71519] * eval.c (PUSH_FRAME): save outer ruby_block. [ruby-list:37677], [ruby-dev:20202] * eval.c (BEGIN_CALLARGS): restore outer block by using ruby_block->outer. * eval.c (block_pass): do not alter block->prev, but block->outer. * array.c (get_inspect_tbl): warning on wrong condition. * eval.c (localjump_xvalue): renamed exitstatus to exit_value since it's not exit "status" after all. * eval.c (localjump_error): add reason to LocalJumpError. * compar.c (rb_cmpint): raise error via rb_cmperr(), if cmp value is nil. now take new 2 arguments. * time.c (time_cmp): 2003-05-16 fix was incomplete. (ruby-bugs-ja:PR#458) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/enum.c b/enum.c
index 6b76f4f..ddefbd6 100644
--- a/enum.c
+++ b/enum.c
@@ -156,23 +156,23 @@ collect_all(i, ary)
}
static VALUE
-enum_to_a(obj)
+enum_collect(obj)
VALUE obj;
{
VALUE ary = rb_ary_new();
- rb_iterate(rb_each, obj, collect_all, ary);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : collect_all, ary);
return ary;
}
static VALUE
-enum_collect(obj)
+enum_to_a(obj)
VALUE obj;
{
VALUE ary = rb_ary_new();
- rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : collect_all, ary);
+ rb_iterate(rb_each, obj, collect_all, ary);
return ary;
}
@@ -264,7 +264,7 @@ sort_by_cmp(a, b)
VALUE retval;
retval = rb_funcall(RARRAY(*a)->ptr[0], id_cmp, 1, RARRAY(*b)->ptr[0]);
- return rb_cmpint(retval);
+ return rb_cmpint(retval, *a, *b);
}
static VALUE
@@ -274,7 +274,12 @@ enum_sort_by(obj)
VALUE ary;
long i;
- ary = rb_ary_new2((TYPE(obj) == T_ARRAY) ? RARRAY(obj)->len : 2000);
+ if (TYPE(obj) == T_ARRAY) {
+ ary = rb_ary_new2(RARRAY(obj)->len);
+ }
+ else {
+ ary = rb_ary_new();
+ }
rb_iterate(rb_each, obj, sort_by_i, ary);
if (RARRAY(ary)->len > 1) {
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp);
@@ -374,7 +379,7 @@ min_i(i, memo)
}
else {
cmp = rb_funcall(i, id_cmp, 1, memo->u1.value);
- if (rb_cmpint(cmp) < 0) {
+ if (rb_cmpint(cmp, i, memo->u1.value) < 0) {
memo->u1.value = i;
}
}
@@ -393,7 +398,7 @@ min_ii(i, memo)
}
else {
cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
- if (rb_cmpint(cmp) < 0) {
+ if (rb_cmpint(cmp, i, memo->u1.value) < 0) {
memo->u1.value = i;
}
}
@@ -425,7 +430,7 @@ max_i(i, memo)
}
else {
cmp = rb_funcall(i, id_cmp, 1, memo->u1.value);
- if (rb_cmpint(cmp) > 0) {
+ if (rb_cmpint(cmp, i, memo->u1.value) > 0) {
memo->u1.value = i;
}
}
@@ -444,7 +449,7 @@ max_ii(i, memo)
}
else {
cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
- if (rb_cmpint(cmp) > 0) {
+ if (rb_cmpint(cmp, i, memo->u1.value) > 0) {
memo->u1.value = i;
}
}