ruby-changes:38763
From: nobu <ko1@a...>
Date: Fri, 12 Jun 2015 17:19:36 +0900 (JST)
Subject: [ruby-changes:38763] nobu:r50844 (trunk): array.c: fix for enumerator
nobu 2015-06-12 17:19:24 +0900 (Fri, 12 Jun 2015) New Revision: 50844 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50844 Log: array.c: fix for enumerator * array.c (rb_ary_bsearch_index): fix function typt to return enumerator if no block given. Modified files: trunk/array.c Index: array.c =================================================================== --- array.c (revision 50843) +++ array.c (revision 50844) @@ -2547,7 +2547,7 @@ rb_ary_sort(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2547 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) https://github.com/ruby/ruby/blob/trunk/array.c#L2605 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; } /* @@ -2627,14 +2629,6 @@ rb_ary_bsearch(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2629 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; VALUE v, val; @@ -2645,7 +2639,7 @@ ary_bsearch_index(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2639 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) https://github.com/ruby/ruby/blob/trunk/array.c#L2652 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) https://github.com/ruby/ruby/blob/trunk/array.c#L2669 low = mid + 1; } } - if (!satisfied) return -1; - return low; + if (!satisfied) return Qnil; + return INT2FIX(low); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/