ruby-changes:51980
From: nagachika <ko1@a...>
Date: Sun, 5 Aug 2018 20:00:03 +0900 (JST)
Subject: [ruby-changes:51980] nagachika:r64195 (ruby_2_5): merge revision(s) 61766: [Backport #14350]
nagachika 2018-08-05 19:59:57 +0900 (Sun, 05 Aug 2018) New Revision: 64195 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64195 Log: merge revision(s) 61766: [Backport #14350] vm_insnhelper.c: search in the indexing order * vm_insnhelper.c (vm_opt_newarray_max, vm_opt_newarray_min): search in the indexing order, as well as usual methods. [ruby-core:84821] [Bug #14350] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/test/ruby/test_array.rb branches/ruby_2_5/version.h branches/ruby_2_5/vm_insnhelper.c Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 64194) +++ ruby_2_5/version.h (revision 64195) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.2" -#define RUBY_RELEASE_DATE "2018-07-02" -#define RUBY_PATCHLEVEL 65 +#define RUBY_RELEASE_DATE "2018-08-05" +#define RUBY_PATCHLEVEL 66 #define RUBY_RELEASE_YEAR 2018 -#define RUBY_RELEASE_MONTH 7 -#define RUBY_RELEASE_DAY 2 +#define RUBY_RELEASE_MONTH 8 +#define RUBY_RELEASE_DAY 5 #include "ruby/version.h" Index: ruby_2_5/vm_insnhelper.c =================================================================== --- ruby_2_5/vm_insnhelper.c (revision 64194) +++ ruby_2_5/vm_insnhelper.c (revision 64195) @@ -3186,16 +3186,15 @@ vm_opt_newarray_max(rb_num_t num, const https://github.com/ruby/ruby/blob/trunk/ruby_2_5/vm_insnhelper.c#L3186 } else { struct cmp_opt_data cmp_opt = { 0, 0 }; - VALUE result = Qundef; + VALUE result = *ptr; rb_num_t i = num - 1; - result = ptr[i]; while (i-- > 0) { - const VALUE v = ptr[i]; - if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) > 0) { + const VALUE v = *++ptr; + if (OPTIMIZED_CMP(v, result, cmp_opt) > 0) { result = v; } } - return result == Qundef ? Qnil : result; + return result; } } else { @@ -3213,16 +3212,15 @@ vm_opt_newarray_min(rb_num_t num, const https://github.com/ruby/ruby/blob/trunk/ruby_2_5/vm_insnhelper.c#L3212 } else { struct cmp_opt_data cmp_opt = { 0, 0 }; - VALUE result = Qundef; + VALUE result = *ptr; rb_num_t i = num - 1; - result = ptr[i]; while (i-- > 0) { - const VALUE v = ptr[i]; - if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) < 0) { + const VALUE v = *++ptr; + if (OPTIMIZED_CMP(v, result, cmp_opt) < 0) { result = v; } } - return result == Qundef ? Qnil : result; + return result; } } else { Index: ruby_2_5/test/ruby/test_array.rb =================================================================== --- ruby_2_5/test/ruby/test_array.rb (revision 64194) +++ ruby_2_5/test/ruby/test_array.rb (revision 64195) @@ -1631,6 +1631,12 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_array.rb#L1631 ary.min(2) {|a,b| a.length <=> b.length }) assert_equal([13, 14], [20, 32, 32, 21, 30, 25, 29, 13, 14].min(2)) assert_equal([2, 4, 6, 7], [2, 4, 8, 6, 7].min(4)) + + class << (obj = Object.new) + def <=>(x) 1 <=> x end + def coerce(x) [x, 1] end + end + assert_same(obj, [obj, 1.0].min) end def test_max @@ -1646,6 +1652,12 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_array.rb#L1652 assert_equal(%w[albatross horse], ary.max(2) {|a,b| a.length <=> b.length }) assert_equal([3, 2], [0, 0, 0, 0, 0, 0, 1, 3, 2].max(2)) + + class << (obj = Object.new) + def <=>(x) 1 <=> x end + def coerce(x) [x, 1] end + end + assert_same(obj, [obj, 1.0].max) end def test_uniq Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 64194) +++ ruby_2_5 (revision 64195) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r61766 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/