* enum.c (min_ii, max_ii, minmax_ii): remove wrong optimization that
reuses array for yield parameter, which caused unexpected behavior. [ruby-core:25989] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9eb49ff8d7
commit
fec209551a
@ -1,3 +1,9 @@
|
|||||||
|
Wed Mar 10 21:25:41 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* enum.c (min_ii, max_ii, minmax_ii): remove wrong optimization that
|
||||||
|
reuses array for yield parameter, which caused unexpected behavior.
|
||||||
|
[ruby-core:25989]
|
||||||
|
|
||||||
Wed Mar 10 12:10:00 2010 Kenta Murata <mrkn@mrkn.jp>
|
Wed Mar 10 12:10:00 2010 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
* enc/x_emoji.h: renamed from enc/x-emoji.c.
|
* enc/x_emoji.h: renamed from enc/x-emoji.c.
|
||||||
|
53
enum.c
53
enum.c
@ -1058,10 +1058,7 @@ min_ii(VALUE i, VALUE *memo, int argc, VALUE *argv)
|
|||||||
*memo = i;
|
*memo = i;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE ary = memo[1];
|
cmp = rb_yield_values(2, i, *memo);
|
||||||
RARRAY_PTR(ary)[0] = i;
|
|
||||||
RARRAY_PTR(ary)[1] = *memo;
|
|
||||||
cmp = rb_yield(ary);
|
|
||||||
if (rb_cmpint(cmp, i, *memo) < 0) {
|
if (rb_cmpint(cmp, i, *memo) < 0) {
|
||||||
*memo = i;
|
*memo = i;
|
||||||
}
|
}
|
||||||
@ -1087,18 +1084,16 @@ min_ii(VALUE i, VALUE *memo, int argc, VALUE *argv)
|
|||||||
static VALUE
|
static VALUE
|
||||||
enum_min(VALUE obj)
|
enum_min(VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE result[2];
|
VALUE result = Qundef;
|
||||||
|
|
||||||
result[0] = Qundef;
|
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
result[1] = rb_ary_new3(2, Qnil, Qnil);
|
rb_block_call(obj, id_each, 0, 0, min_ii, (VALUE)&result);
|
||||||
rb_block_call(obj, id_each, 0, 0, min_ii, (VALUE)result);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_block_call(obj, id_each, 0, 0, min_i, (VALUE)result);
|
rb_block_call(obj, id_each, 0, 0, min_i, (VALUE)&result);
|
||||||
}
|
}
|
||||||
if (result[0] == Qundef) return Qnil;
|
if (result == Qundef) return Qnil;
|
||||||
return result[0];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -1131,10 +1126,7 @@ max_ii(VALUE i, VALUE *memo, int argc, VALUE *argv)
|
|||||||
*memo = i;
|
*memo = i;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE ary = memo[1];
|
cmp = rb_yield_values(2, i, *memo);
|
||||||
RARRAY_PTR(ary)[0] = i;
|
|
||||||
RARRAY_PTR(ary)[1] = *memo;
|
|
||||||
cmp = rb_yield(ary);
|
|
||||||
if (rb_cmpint(cmp, i, *memo) > 0) {
|
if (rb_cmpint(cmp, i, *memo) > 0) {
|
||||||
*memo = i;
|
*memo = i;
|
||||||
}
|
}
|
||||||
@ -1159,24 +1151,21 @@ max_ii(VALUE i, VALUE *memo, int argc, VALUE *argv)
|
|||||||
static VALUE
|
static VALUE
|
||||||
enum_max(VALUE obj)
|
enum_max(VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE result[2];
|
VALUE result = Qundef;
|
||||||
|
|
||||||
result[0] = Qundef;
|
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
result[1] = rb_ary_new3(2, Qnil, Qnil);
|
rb_block_call(obj, id_each, 0, 0, max_ii, (VALUE)&result);
|
||||||
rb_block_call(obj, id_each, 0, 0, max_ii, (VALUE)result);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_block_call(obj, id_each, 0, 0, max_i, (VALUE)result);
|
rb_block_call(obj, id_each, 0, 0, max_i, (VALUE)&result);
|
||||||
}
|
}
|
||||||
if (result[0] == Qundef) return Qnil;
|
if (result == Qundef) return Qnil;
|
||||||
return result[0];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct minmax_t {
|
struct minmax_t {
|
||||||
VALUE min;
|
VALUE min;
|
||||||
VALUE max;
|
VALUE max;
|
||||||
VALUE ary;
|
|
||||||
VALUE last;
|
VALUE last;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1242,17 +1231,11 @@ minmax_ii_update(VALUE i, VALUE j, struct minmax_t *memo)
|
|||||||
memo->max = j;
|
memo->max = j;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE ary = memo->ary;
|
n = rb_cmpint(rb_yield_values(2, i, memo->min), i, memo->min);
|
||||||
|
|
||||||
rb_ary_store(ary, 0, i);
|
|
||||||
rb_ary_store(ary, 1, memo->min);
|
|
||||||
n = rb_cmpint(rb_yield(ary), i, memo->min);
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
memo->min = i;
|
memo->min = i;
|
||||||
}
|
}
|
||||||
rb_ary_store(ary, 0, j);
|
n = rb_cmpint(rb_yield_values(2, j, memo->max), j, memo->max);
|
||||||
rb_ary_store(ary, 1, memo->max);
|
|
||||||
n = rb_cmpint(rb_yield(ary), j, memo->max);
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
memo->max = j;
|
memo->max = j;
|
||||||
}
|
}
|
||||||
@ -1264,7 +1247,7 @@ minmax_ii(VALUE i, VALUE _memo, int argc, VALUE *argv)
|
|||||||
{
|
{
|
||||||
struct minmax_t *memo = (struct minmax_t *)_memo;
|
struct minmax_t *memo = (struct minmax_t *)_memo;
|
||||||
int n;
|
int n;
|
||||||
VALUE ary, j;
|
VALUE j;
|
||||||
|
|
||||||
ENUM_WANT_SVALUE();
|
ENUM_WANT_SVALUE();
|
||||||
|
|
||||||
@ -1275,10 +1258,7 @@ minmax_ii(VALUE i, VALUE _memo, int argc, VALUE *argv)
|
|||||||
j = memo->last;
|
j = memo->last;
|
||||||
memo->last = Qundef;
|
memo->last = Qundef;
|
||||||
|
|
||||||
ary = memo->ary;
|
n = rb_cmpint(rb_yield_values(2, j, i), j, i);
|
||||||
rb_ary_store(ary, 0, j);
|
|
||||||
rb_ary_store(ary, 1, i);
|
|
||||||
n = rb_cmpint(rb_yield(ary), j, i);
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
i = j;
|
i = j;
|
||||||
else if (n < 0) {
|
else if (n < 0) {
|
||||||
@ -1317,7 +1297,6 @@ enum_minmax(VALUE obj)
|
|||||||
memo.min = Qundef;
|
memo.min = Qundef;
|
||||||
memo.last = Qundef;
|
memo.last = Qundef;
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
memo.ary = ary;
|
|
||||||
rb_block_call(obj, id_each, 0, 0, minmax_ii, (VALUE)&memo);
|
rb_block_call(obj, id_each, 0, 0, minmax_ii, (VALUE)&memo);
|
||||||
if (memo.last != Qundef)
|
if (memo.last != Qundef)
|
||||||
minmax_ii_update(memo.last, memo.last, &memo);
|
minmax_ii_update(memo.last, memo.last, &memo);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user