summaryrefslogtreecommitdiff
path: root/enum.c
AgeCommit message (Collapse)Author
2018-10-30introduce TransientHeap. [Bug #14858]ko1
* 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
2018-10-30* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30revert r65444 and r65446 because of commit missko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30introduce TransientHeap. [Bug #14858]ko1
* 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
2018-10-29use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko1
* 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
2018-10-10revisit `RARRAY_PTR()`.ko1
* 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
2018-09-21Fix a typo [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20Enumerable#to_h with block and so onnobu
[Feature #15143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13warn unused blocks with Enumerable#all? any? one? none?nobu
[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
2018-07-24UNREACHABLE_RETURNnobu
* 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
2018-07-22fix sum on infinitynobu
* 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
2018-06-02enum.c: bignum counternobu
* 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
2018-06-02enum.c: mitigate overflowsnobu
* 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
2018-06-02memo->u3.cnt is long not int [Bug #14805]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25Add a new #filter alias for #selecteregon
* 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
2018-02-13Fixing some minimal formating on enum.c examplesnobu
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
2018-01-19INFINITY is float. That of double is HUGE_VAL.shyouhei
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
2018-01-09internal.h: remove dependecy on ruby/encoding.hnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14enum.c: improve docs for Enumerable#{any?,all?,none?,one?}stomar
* 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
2017-12-12Add more example of `Enumerable#one?` [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-10Add case equality arity to Enumerable#all?, any?, none? and one?,marcandre
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
2017-11-05enum.c: check argument firstnobu
* 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
2017-11-05Fix size on Enumerable#cycle when the size is 0 [Bug #14082].marcandre
Patch by Kenichi Kamiya git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-11enum.c: make constant argument staticnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-07enum.c: optimize for integersnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-07enum.c: prefer rb_funcallv to rb_funcallnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-07enum.c: use predefined IDsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-18vm_eval.c: rb_lambda_callnobu
* 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
2017-06-21Fix Enumerable#uniq with non single yield argumentsnobu
* 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
2017-06-05rename functions and clean parameters.ko1
* 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
2017-05-30enum.c: check if reenterednobu
* 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
2017-05-30enum.c: rb_check_funcall_default for fallback valuenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-30Improve performance of Enumerable#{sort_by,min_by,max_by,minmax_by}watson1978
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
2017-05-24enum.c: respect method visibilitynobu
* 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
2017-03-19vm_args.c: arity check of lambdanobu
* 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
2017-03-04documentation for sort methodsstomar
* 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
2017-03-04enum.c: documentation for Enumerable#sort_bystomar
* 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
2017-02-09[DOC] Update an obsolete example for slice_before.akr
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
2017-01-27enum.c: write barriernobu
* 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
2017-01-27enum.c (rb_nmin_run): adjust indent [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-27Enumerable#{min,min_by,max,max_by} [ci skip]nobu
* 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
2017-01-25[DOC] Add empty example to enum.all? and any?kazu
[ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06array.c, enum.c: change sum algorithmmrkn
* 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
2016-10-13unstable sort [ci skip]nobu
* 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
2016-10-06* enum.c: [DOC] Improve doc [ci-skip]marcandre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-06* enum.c: Add reduce/inject alias note.hsbt
[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
2016-10-04* enum.c: Make Enumerable#chunk with no block returnmarcandre
an Enumerator [#2172] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-24fid typos [ci skip]nobu
* 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
2016-08-20enum.c (enum_sort): prevent wasteful array duplicaionmrkn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-20enum.c: [DOC] Enumerable#uniq [ci skip]nobu
* 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