зеркало из https://github.com/github/ruby.git
* array.c (rb_ary_max, rb_ary_min): implement a block by itself instead
of delegating Enumerable#max/min. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
68a6f2e9e0
Коммит
90ab5beb42
|
@ -1,3 +1,8 @@
|
|||
Thu Mar 17 21:24:52 2016 Yusuke Endoh <mame@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_max, rb_ary_min): implement a block by itself instead
|
||||
of delegating Enumerable#max/min.
|
||||
|
||||
Thu Mar 17 21:09:34 2016 Yusuke Endoh <mame@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_max, rb_ary_min): Array#max and Array#min added.
|
||||
|
|
44
array.c
44
array.c
|
@ -4210,14 +4210,24 @@ rb_ary_max(int argc, VALUE *argv, VALUE ary)
|
|||
|
||||
rb_scan_args(argc, argv, "01", &num);
|
||||
|
||||
if (!NIL_P(num) || rb_block_given_p())
|
||||
if (!NIL_P(num))
|
||||
return rb_call_super(argc, argv); /* XXX: should redefine? */
|
||||
|
||||
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||
v = RARRAY_AREF(ary, i);
|
||||
if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) > 0) {
|
||||
result = v;
|
||||
}
|
||||
if (rb_block_given_p()) {
|
||||
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||
v = RARRAY_AREF(ary, i);
|
||||
if (result == Qundef || rb_cmpint(rb_yield_values(2, v, result), v, result) > 0) {
|
||||
result = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||
v = RARRAY_AREF(ary, i);
|
||||
if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) > 0) {
|
||||
result = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == Qundef) return Qnil;
|
||||
return result;
|
||||
|
@ -4255,14 +4265,24 @@ rb_ary_min(int argc, VALUE *argv, VALUE ary)
|
|||
|
||||
rb_scan_args(argc, argv, "01", &num);
|
||||
|
||||
if (!NIL_P(num) || rb_block_given_p())
|
||||
if (!NIL_P(num))
|
||||
return rb_call_super(argc, argv); /* XXX: should redefine? */
|
||||
|
||||
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||
v = RARRAY_AREF(ary, i);
|
||||
if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) < 0) {
|
||||
result = v;
|
||||
}
|
||||
if (rb_block_given_p()) {
|
||||
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||
v = RARRAY_AREF(ary, i);
|
||||
if (result == Qundef || rb_cmpint(rb_yield_values(2, v, result), v, result) < 0) {
|
||||
result = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||
v = RARRAY_AREF(ary, i);
|
||||
if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) < 0) {
|
||||
result = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == Qundef) return Qnil;
|
||||
return result;
|
||||
|
|
Загрузка…
Ссылка в новой задаче