aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix Enumerable#uniq with non single yield argumentsnobu2017-06-211-0/+2
| | | | | | | | | * enum.c (uniq_func, uniq_iter): need packed value as the unique key. [ruby-core:81734] [Bug #13669] [Fix GH-1658] Author: Kenichi Kamiya <kachick1@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rename functions and clean parameters.ko12017-06-051-2/+2
| | | | | | | | | | | | | | | | | | | | | * internal.h (rb_yield_lambda): rename to rb_yield_force_blockarg() because this function prohibt lambda arg setup (strict setup). * vm.c (invoke_iseq_block_from_c): remove splattable argument because it is not used. * vm.c (invoke_block_from_c_splattable): rename to invoke_block_from_c_bh() because `splattable` doesn't make sense on current this function. Also accept `force_blockarg' parameter instead of `splattable` parameter. It is more clear. * vm.c (invoke_block_from_c_unsplattable): rename to invoke_block_from_c_proc() and accept `proc` instead of `block'. This function is used only by proc block invocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: check if reenterednobu2017-05-301-7/+12
| | | | | | | | | | * enum.c (cmpint_reenter_check): extract from nmin_cmp and nmin_block_cmp. * enum.c (nmin_cmp): check if reentered before rb_cmpint. [Feature #13437] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: rb_check_funcall_default for fallback valuenobu2017-05-301-3/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of Enumerable#{sort_by,min_by,max_by,minmax_by}watson19782017-05-301-8/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is totally same approach with r58964. enum.c (sort_by_cmp): use OPTIMIZED_CMP() to compare the objects instead of `<=>' method dispatching for Fixnum/Float/String object. enum.c (nmin_cmp): ditto. enum.c (min_by_i): ditto. enum.c (max_by_i): ditto. enum.c (minmax_by_i_update): ditto. enum.c (minmax_by_i): ditto. Enumerable#sort_by -> 51 % up Enumerable#min_by(n) -> 34 % up Enumerable#min_by -> 37 % up Enumerable#max_by(n) -> 61 % up Enumerable#max_by -> 40 % up Enumerable#minmax_by -> 67 % up [ruby-core:80689] [Bug #13437] [Fix GH-1584] ### Before Enumerable#sort_by 5.692k (± 2.2%) i/s - 28.611k in 5.028861s Enumerable#min_by(n) 8.496k (± 0.5%) i/s - 43.146k in 5.078394s Enumerable#min_by 8.678k (± 0.5%) i/s - 43.911k in 5.060128s Enumerable#max_by(n) 3.306k (± 3.0%) i/s - 16.562k in 5.014727s Enumerable#max_by 8.322k (± 2.8%) i/s - 42.400k in 5.099400s Enumerable#minmax_by 6.769k (± 2.6%) i/s - 34.100k in 5.041354s ### After Enumerable#sort_by 8.591k (± 3.0%) i/s - 43.316k in 5.046836s Enumerable#min_by(n) 11.489k (± 1.2%) i/s - 57.732k in 5.025504s Enumerable#min_by 11.835k (± 2.7%) i/s - 60.150k in 5.086450s Enumerable#max_by(n) 5.322k (± 1.1%) i/s - 26.650k in 5.008289s Enumerable#max_by 11.705k (± 0.6%) i/s - 59.262k in 5.062997s Enumerable#minmax_by 11.323k (± 1.3%) i/s - 57.018k in 5.036565s ### Test code require 'benchmark/ips' Benchmark.ips do |x| enum = (1..1000).to_a.to_enum x.report "Enumerable#sort_by" do enum.sort_by { |a| a } end x.report "Enumerable#min_by(n)" do enum.min_by(2) { |a| a } end x.report "Enumerable#min_by" do enum.min_by { |a| a } end x.report "Enumerable#max_by(n)" do enum.max_by(2) { |a| a } end x.report "Enumerable#max_by" do enum.max_by { |a| a } end x.report "Enumerable#minmax_by" do enum.minmax_by { |a| a } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: respect method visibilitynobu2017-05-241-3/+4
| | | | | | | * enum.c (ary_inject_op): should respect method visibility, do not optimize uncallable method. [ruby-core:81349] [Bug #13592] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_args.c: arity check of lambdanobu2017-03-191-25/+45
| | | | | | | | | | | | * vm_eval.c (rb_yield_lambda): new function which yields an array to a proc and splat to a lambda. mainly for Enumerable only. * vm_args.c (setup_parameters_complex): remove special lambda splatting for [Bug #9605]. [ruby-core:77065] [Bug #12705] * vm_insnhelper.c (vm_callee_setup_block_arg): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* documentation for sort methodsstomar2017-03-041-2/+2
| | | | | | | | * array.c: [DOC] fix grammar in Array#sort, #sort!, #sort_by!, move references below the code example, add a missing reference. * enum.c: [DOC] fix grammar in Enumerable#sort, #sort_by. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: documentation for Enumerable#sort_bystomar2017-03-041-10/+14
| | | | | | | | * enum.c: [DOC] improve structure of docs for Enumerable#sort_by, adopt explanation of the comparison block from Array#sort_by, drop mention of 1.8, fix typos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] Update an obsolete example for slice_before.akr2017-02-091-3/+4
| | | | | | | | | | The argument for Enumerable#slice_before is is removed at Ruby 2.3. Reported by Shyouhei Urabe. [Bug #13202] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: write barriernobu2017-01-271-1/+1
| | | | | | * enum.c (rb_nmin_run): set the class with write barrier. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c (rb_nmin_run): adjust indent [ci skip]nobu2017-01-271-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Enumerable#{min,min_by,max,max_by} [ci skip]nobu2017-01-271-5/+9
| | | | | | | | | | | | * enum.c: [DOC] Enumerable#{min,min_by,max,max_by} return a sorted array when +n+ argument is used. * enum.c: Small typo : minimum -> maximum [Bug #13161] Author: Eric Duminil <eric.duminil@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] Add empty example to enum.all? and any?kazu2017-01-251-0/+2
| | | | | | [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c, enum.c: change sum algorithmmrkn2016-12-061-6/+11
| | | | | | | | | | | | * array.c (rb_ary_sum): change the algorithm to Kahan-Babuska balancing summation to be more precise. [Feature #12871] [ruby-core:77771] * enum.c (sum_iter, enum_sum): ditto. * test_array.rb, test_enum.rb: add an assertion for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* unstable sort [ci skip]nobu2016-10-131-0/+6
| | | | | | | | * array.c (rb_ary_sort_bang, rb_ary_sort, rb_ary_sort_by_bang): [DOC] describe that sort may not be stable. * enum.c (enum_sort, enum_sort_by): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c: [DOC] Improve doc [ci-skip]marcandre2016-10-061-5/+9
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c: Add reduce/inject alias note.hsbt2016-10-061-0/+3
| | | | | | [fix GH-1400][ci skip] Patch by @getaaron git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c: Make Enumerable#chunk with no block returnmarcandre2016-10-041-2/+2
| | | | | | an Enumerator [#2172] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fid typos [ci skip]nobu2016-09-241-2/+2
| | | | | | * fix typos, "a" before "Integer" to "an". [Fix GH-1438] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c (enum_sort): prevent wasteful array duplicaionmrkn2016-08-201-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: [DOC] Enumerable#uniq [ci skip]nobu2016-07-201-0/+4
| | | | | | | * enum.c (enum_uniq): add rdoc, reference to Array#uniq. [Feature #11090] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: Enumerable#uniqnobu2016-07-201-0/+35
| | | | | | | * enum.c (enum_uniq): new method Enumerable#uniq. [Feature #11090] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* exclude non-VALUE in memo from GCnobu2016-05-201-4/+5
| | | | | | | | | | | * internal.h (NEW_PARTIAL_MEMO_FOR): shrink buffer array not to mark non-VALUE fields. fix check_rvalue_consistency abort with RGENGC_CHECK_MODE=2. * internal.h (NEW_CMP_OPT_MEMO): exclude struct cmp_opt_data from the valid array range. * enum.c (slicewhen_i): exclude inverted too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: fix declaration-after-statementnobu2016-05-181-1/+2
| | | | | | | * enum.c (sum_iter): workaround of mixed declarations and code. erred by -Werror=declaration-after-statement option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Optimize each_sum for hashesmrkn2016-05-181-6/+33
| | | | | | | * enum.c (enum_sum, hash_sum, hash_sum_i, enum_sum_i, sum_iter): Optimize for hashes when each method isn't redefined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Extract int_range_sum from enum_summrkn2016-05-181-16/+21
| | | | | | | * enum.c (enum_sum, int_range_sum): Extract int_range_sum from enum_sum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Optimize enum_sum for a range from int to intmrkn2016-05-171-0/+25
| | | | | | | | | | | | | * enum.c (enum_sum): Optimize for a range from int to int. * test/ruby/test_enum.rb (test_range_sum): Move from test_range.rb, and add assertions for some conditions. * test/ruby/test_enum.rb (test_hash_sum): Move from test_hash.rb. * test/ruby/test_hash.rb, test/ruby/test_range.rb: Remove test_sum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Write document of Enumerable#summrkn2016-05-171-0/+26
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Implement Enumerable#summrkn2016-05-171-0/+148
| | | | | | | | | | | | * enum.c (enum_sum): Implement Enumerable#sum. * test/ruby/test_enum.rb (test_sum): Test sum for Enumerable. * test/ruby/test_hash.rb (test_sum): Test sum for Hash. * test/ruby/test_range.rb (test_sum): Test sum for Range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Use Integer instead of Fixnum and Bignum.akr2016-05-171-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | * object.c, numeric.c, enum.c, ext/-test-/bignum/mul.c, lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rexml/xpath_parser.rb, lib/rubygems/specification.rb, lib/uri/generic.rb, bootstraptest/test_eval.rb, basictest/test.rb, test/-ext-/bignum/test_big2str.rb, test/-ext-/bignum/test_div.rb, test/-ext-/bignum/test_mul.rb, test/-ext-/bignum/test_str2big.rb, test/csv/test_data_converters.rb, test/date/test_date.rb, test/json/test_json_generate.rb, test/minitest/test_minitest_mock.rb, test/openssl/test_cipher.rb, test/rexml/test_jaxen.rb, test/ruby/test_array.rb, test/ruby/test_basicinstructions.rb, test/ruby/test_bignum.rb, test/ruby/test_case.rb, test/ruby/test_class.rb, test/ruby/test_complex.rb, test/ruby/test_enum.rb, test/ruby/test_eval.rb, test/ruby/test_iseq.rb, test/ruby/test_literal.rb, test/ruby/test_math.rb, test/ruby/test_module.rb, test/ruby/test_numeric.rb, test/ruby/test_range.rb, test/ruby/test_rational.rb, test/ruby/test_refinement.rb, test/ruby/test_rubyvm.rb, test/ruby/test_struct.rb, test/ruby/test_variable.rb, test/rubygems/test_gem_specification.rb, test/thread/test_queue.rb: Use Integer instead of Fixnum and Bignum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: examples of Enumerable#detect [ci skip]nobu2016-05-051-0/+5
| | | | | | | | * enum.c (enum_find): [DOC] add more examples to the documentation of Enumerable#detect, to show that it equals to Enumerable#find. [Fix GH-1340] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c (rb_ary_sum): Array#sum is implemented.akr2016-04-131-40/+8
| | | | | | | | | | | | | Kahan's compensated summation algorithm for precise sum of float numbers is moved from ary_inject_op in enum.c. * enum.c (ary_inject_op): Don't specialize for float numbers. [ruby-core:74569] [Feature#12217] proposed by mrkn. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (ary_inject_op): put subtract operation out of if-clause.mrkn2016-03-231-4/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (ary_inject_op): Use Kahan's compensated summation algorithmmrkn2016-03-231-4/+11
| | | | | | for summing up float values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (ary_inject_op): Implement the specialized code for sum ofakr2016-03-171-26/+40
| | | | | | | | float numbers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c, enum.c: make rdoc format consistent.mame2016-03-171-7/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c (rb_ary_max, rb_ary_min): implement Array#max and min withmame2016-03-171-7/+17
| | | | | | | | | | arguments. replace super call with rb_nmin_run. * enum.c (nmin_run): exported (as rb_nmin_run). * internal.h: added a prototype for rb_nmin_run. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c (rb_ary_max, rb_ary_min): Array#max and Array#min added.mame2016-03-171-7/+0
| | | | | | | | | | | | | | | [Feature #12172] * internal.h (OPTIMIZED_CMP): moved from enum.c so that array.c can use it. * test/ruby/test_array.rb (test_max, test_min): tests for Array#max and Array#min. * test/ruby/test_enum.rb (test_max, test_min): revised a bit to test Enumerable#max and #min explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.c: struct cmp_opt_data added for refactoring out a datamame2016-03-171-17/+14
| | | | | | | | | | structure for CMP_OPTIMIZABLE * array.c (struct ary_sort_data): use struct cmp_opt_data. * enum.c (struct min_t, max_t, min_max_t): use struct cmp_opt_data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (ary_inject_op): Extracted from enum_inject.akr2016-03-171-57/+67
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_inject): Implement the specialized code for sum ofakr2016-03-171-10/+38
| | | | | | | | | | | | integers including Bignums. * internal.h (rb_fix_plus): Declared to be usable from enum_inject. * numeric.c (rb_fix_plus): Defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_inject): Consider redefinition of Fixnum#+.akr2016-03-151-1/+2
| | | | | | | | [ruby-dev:49510] [Bug#12178] Reported by usa. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_inject): Implement the specialied code for :+ operatorakr2016-03-151-0/+11
| | | | | | | for Fixnums. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_inject): Implement the specialized code for self is anakr2016-03-151-0/+24
| | | | | | | array and a symbol operator is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Rename parameter namenobu2016-01-291-2/+2
| | | | | | | * enum.c (enum_take_while, enum_drop_while): rename block parameter to obj, since they are generic objects. [Fix GH-1226] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_min, enum_max): do the same optimization as r53454.shugo2016-01-071-50/+58
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_minmax): optimize object comparison inshugo2016-01-071-10/+27
| | | | | | Enumerable#minmax. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c: fix a typo in documentation.hsbt2015-12-141-1/+1
| | | | | | | | | | | | [ci skip][fix GH-1140] Patch by @jutaz * io.c: ditto. * iseq.c: ditto. * numeric.c: ditto. * process.c: ditto. * string.c: ditto. * vm_trace.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add a comment.akr2015-10-041-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e