aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
Commit message (Collapse)AuthorAgeFilesLines
* introduce TransientHeap. [Bug #14858]ko12018-10-301-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * transient_heap.c, transient_heap.h: implement TransientHeap (theap). theap is designed for Ruby's object system. theap is like Eden heap on generational GC terminology. theap allocation is very fast because it only needs to bump up pointer and deallocation is also fast because we don't do anything. However we need to evacuate (Copy GC terminology) if theap memory is long-lived. Evacuation logic is needed for each type. See [Bug #14858] for details. * array.c: Now, theap for T_ARRAY is supported. ary_heap_alloc() tries to allocate memory area from theap. If this trial sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on. We don't need to free theap ptr. * ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that if ary is allocated at theap, force evacuation to malloc'ed memory. It makes programs slow, but very compatible with current code because theap memory can be evacuated (theap memory will be recycled). If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT() instead of RARRAY_CONST_PTR(). If you can't understand when evacuation will occur, use RARRAY_CONST_PTR(). (re-commit of r65444) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2018-10-301-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revert r65444 and r65446 because of commit missko12018-10-301-5/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* introduce TransientHeap. [Bug #14858]ko12018-10-301-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * transient_heap.c, transient_heap.h: implement TransientHeap (theap). theap is designed for Ruby's object system. theap is like Eden heap on generational GC terminology. theap allocation is very fast because it only needs to bump up pointer and deallocation is also fast because we don't do anything. However we need to evacuate (Copy GC terminology) if theap memory is long-lived. Evacuation logic is needed for each type. See [Bug #14858] for details. * array.c: Now, theap for T_ARRAY is supported. ary_heap_alloc() tries to allocate memory area from theap. If this trial sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on. We don't need to free theap ptr. * ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that if ary is allocated at theap, force evacuation to malloc'ed memory. It makes programs slow, but very compatible with current code because theap memory can be evacuated (theap memory will be recycled). If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT() instead of RARRAY_CONST_PTR(). If you can't understand when evacuation will occur, use RARRAY_CONST_PTR(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko12018-10-291-1/+2
| | | | | | | | | * class.c (rb_keyword_error_new): use RARRAY_AREF() because RARRAY_CONST_PTR() can introduce additional overhead in a futre. Same fixes for other files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revisit `RARRAY_PTR()`.ko12018-10-101-10/+14
| | | | | | | | | | | | | | | * array.c (yield_indexed_values): use RARRAY_AREF/ASET instead of using RARRAY_PTR(). * enum.c (nmin_filter): ditto. * proc.c (rb_sym_to_proc): ditto. * enum.c (rb_nmin_run): use RARRAY_PTR_USE() instead of RARRAY_PTR(). It is safe because they don't make new referecen from an array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix a typo [ci skip]kazu2018-09-211-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Enumerable#to_h with block and so onnobu2018-09-201-14/+18
| | | | | | [Feature #15143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* warn unused blocks with Enumerable#all? any? one? none?nobu2018-09-131-0/+11
| | | | | | | | [Fix GH-1953] From: Koji Onishi <fursich0@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* UNREACHABLE_RETURNnobu2018-07-241-1/+1
| | | | | | | * include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end of non-void functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix sum on infinitynobu2018-07-221-0/+19
| | | | | | | | | * array.c (rb_ary_sum): consider non-finite floats. [ruby-core:88024] [Bug #14926] * enum.c (sum_iter): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: bignum counternobu2018-06-021-10/+40
| | | | | | | * enum.c (imemo_count_up, imemo_count_value): promote the counter value to a bignum on overflow. [Bug #14805] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: mitigate overflowsnobu2018-06-021-5/+5
| | | | | | | | | | | | | | | * enum.c (enum_count): convert counters to Integer as unsigned long, instead of long, to mitigate overflows. [ruby-core:87348] [Bug #14805] * enum.c (ary_inject_op): ditto. * enum.c (each_with_index_i): ditto, instead of int. * enum.c (find_index_i, find_index_iter_i): ditto, instead of unsigned int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* memo->u3.cnt is long not int [Bug #14805]naruse2018-06-021-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a new #filter alias for #selecteregon2018-02-251-0/+5
| | | | | | | | | | | | | | | * In Enumerable, Enumerator::Lazy, Array, Hash and Set [Feature #13784] [ruby-core:82285] * Share specs for the various #select#select! methods and reuse them for #filter/#filter!. * Add corresponding filter tests for select tests. * Update NEWS. [Fix GH-1824] From: Alexander Patrick <adp90@case.edu> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fixing some minimal formating on enum.c examplesnobu2018-02-131-11/+11
| | | | | | | | | | | This will fix the formatting shown on detect|find and revese_arch generated by RDoc. [Fix GH-1816] From: Espartaco Palma <esparta@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* INFINITY is float. That of double is HUGE_VAL.shyouhei2018-01-191-1/+1
| | | | | | | | | | It seems HUGE_VAL is already used. Why not eliminate INTINITY. NAN is also float. That of double is called nan(). This is also fixed. Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: remove dependecy on ruby/encoding.hnobu2018-01-091-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: improve docs for Enumerable#{any?,all?,none?,one?}stomar2017-12-141-4/+4
| | | | | | | | * enum.c: [DOC] reword docs for Enumerable#{any?,all?,none?,one?} to not mention the receiver (`enum') from call-seq, because it does not appear in the call-seq of the rendered HTML docs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add more example of `Enumerable#one?` [ci skip]kazu2017-12-121-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add case equality arity to Enumerable#all?, any?, none? and one?,marcandre2017-12-101-13/+46
| | | | | | | and specialized Array#any? and Hash#any? Based on patch by D.E. Akers [#11286] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: check argument firstnobu2017-11-051-7/+8
| | | | | | | * enum.c (enum_cycle_size): check an argument before the size of the receiver, if it is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix size on Enumerable#cycle when the size is 0 [Bug #14082].marcandre2017-11-051-0/+1
| | | | | | Patch by Kenichi Kamiya git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: make constant argument staticnobu2017-08-111-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: optimize for integersnobu2017-08-071-4/+22
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: prefer rb_funcallv to rb_funcallnobu2017-08-071-24/+35
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: use predefined IDsnobu2017-08-071-4/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_eval.c: rb_lambda_callnobu2017-07-181-1/+3
| | | | | | | | | | | | | * enum.c (enum_collect): make the block arity same as the given block. [Bug #13391] * internal.h (vm_ifunc): store arity instead of unused id. * proc.c (rb_vm_block_min_max_arity): return ifunc arity. * vm_eval.c (rb_lambda_call): call method with lambda block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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