1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

array.c: improve performance of Array#sort with block

* array.c (sort_1): improve performance of Array#sort with block

* benchmark/bm_array_sort_block.rb: added for Array#sort with block

[Bug #13344]
[ruby-dev:50027]
[Fix GH-1544]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2017-04-13 09:25:38 +00:00
parent 53430e355a
commit cb8012f5c0
2 changed files with 6 additions and 1 deletions

View file

@ -2396,9 +2396,12 @@ sort_1(const void *ap, const void *bp, void *dummy)
struct ary_sort_data *data = dummy;
VALUE retval = sort_reentered(data->ary);
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
VALUE args[2];
int n;
retval = rb_yield_values(2, a, b);
args[0] = a;
args[1] = b;
retval = rb_yield_values2(2, args);
n = rb_cmpint(retval, a, b);
sort_reentered(data->ary);
return n;

View file

@ -0,0 +1,2 @@
ary = Array.new(1000) { rand(1000) }
10000.times { ary.sort { |a, b| a <=> b } }