mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
array.c: fix for enumerator
* array.c (rb_ary_bsearch_index): fix function typt to return enumerator if no block given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b3bc21b53
commit
c54fb9ec8b
1 changed files with 10 additions and 16 deletions
26
array.c
26
array.c
|
@ -2547,7 +2547,7 @@ rb_ary_sort(VALUE ary)
|
|||
return ary;
|
||||
}
|
||||
|
||||
static long ary_bsearch_index(VALUE ary);
|
||||
static VALUE rb_ary_bsearch_index(VALUE ary);
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
|
@ -2605,10 +2605,12 @@ static long ary_bsearch_index(VALUE ary);
|
|||
static VALUE
|
||||
rb_ary_bsearch(VALUE ary)
|
||||
{
|
||||
long index_result = ary_bsearch_index(ary);
|
||||
VALUE index_result = rb_ary_bsearch_index(ary);
|
||||
|
||||
if (index_result < 0) return rb_ary_entry(ary, index_result);
|
||||
return INT2FIX(index_result);
|
||||
if (FIXNUM_P(index_result)) {
|
||||
return rb_ary_entry(ary, FIX2LONG(index_result));
|
||||
}
|
||||
return index_result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2626,14 +2628,6 @@ rb_ary_bsearch(VALUE ary)
|
|||
|
||||
static VALUE
|
||||
rb_ary_bsearch_index(VALUE ary)
|
||||
{
|
||||
long index_result = ary_bsearch_index(ary);
|
||||
|
||||
return INT2FIX(index_result);
|
||||
}
|
||||
|
||||
static long
|
||||
ary_bsearch_index(VALUE ary)
|
||||
{
|
||||
long low = 0, high = RARRAY_LEN(ary), mid;
|
||||
int smaller = 0, satisfied = 0;
|
||||
|
@ -2645,7 +2639,7 @@ ary_bsearch_index(VALUE ary)
|
|||
val = rb_ary_entry(ary, mid);
|
||||
v = rb_yield(val);
|
||||
if (FIXNUM_P(v)) {
|
||||
if (v == INT2FIX(0)) return mid;
|
||||
if (v == INT2FIX(0)) return INT2FIX(mid);
|
||||
smaller = (SIGNED_VALUE)v < 0; /* Fixnum preserves its sign-bit */
|
||||
}
|
||||
else if (v == Qtrue) {
|
||||
|
@ -2658,7 +2652,7 @@ ary_bsearch_index(VALUE ary)
|
|||
else if (rb_obj_is_kind_of(v, rb_cNumeric)) {
|
||||
const VALUE zero = INT2FIX(0);
|
||||
switch (rb_cmpint(rb_funcallv(v, id_cmp, 1, &zero), v, zero)) {
|
||||
case 0: return mid;
|
||||
case 0: return INT2FIX(mid);
|
||||
case 1: smaller = 1; break;
|
||||
case -1: smaller = 0;
|
||||
}
|
||||
|
@ -2675,8 +2669,8 @@ ary_bsearch_index(VALUE ary)
|
|||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
if (!satisfied) return -1;
|
||||
return low;
|
||||
if (!satisfied) return Qnil;
|
||||
return INT2FIX(low);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue