summaryrefslogtreecommitdiff
path: root/array.c
AgeCommit message (Collapse)Author
2022-08-11Fix Array#[] with ArithmeticSequence with negative steps (#5739)Jeremy Evans
* Fix Array#[] with ArithmeticSequence with negative steps Previously, Array#[] when called with an ArithmeticSequence with a negative step did not handle all cases correctly, especially cases involving infinite ranges, inverted ranges, and/or exclusive ends. Fixes [Bug #18247] * Add Array#slice tests for ArithmeticSequence with negative step to test_array Add tests of rb_arithmetic_sequence_beg_len_step C-API function. * Fix ext/-test-/arith_seq/beg_len_step/depend * Rename local variables * Fix a variable name Co-authored-by: Kenta Murata <3959+mrkn@users.noreply.github.com> Notes: Merged-By: mrkn <mrkn@ruby-lang.org>
2022-07-28Make array slices views rather than copiesPeter Zhu
Before this commit, if the slice fits in VWA, it would make a copy rather than a view. This is slower as it requires a memcpy of the contents. Notes: Merged: https://github.com/ruby/ruby/pull/6192
2022-07-26Use rb_ary_hidden_new for rb_ary_hidden_new_fillPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-26Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu
rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new. Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-26Remove ary_discardPeter Zhu
ary_discard should not be used as it should be handled by the GC. The only user of ary_discard is rb_ary_product, which doesn't neeed to use ary_discard. Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-22Remove reference counting for all frozen arraysPeter Zhu
The RARRAY_LITERAL_FLAG was added in commit 5871ecf956711fcacad7c03f2aef95115ed25bc4 to improve CoW performance for array literals by not keeping track of reference counts. This commit reverts that commit and has an alternate implementation that is more generic for all frozen arrays. Since frozen arrays cannot be modified, we don't need to set the RARRAY_SHARED_ROOT_FLAG and we don't need to do reference counting. Notes: Merged: https://github.com/ruby/ruby/pull/6171
2022-07-21Remove unused variable in array.cPeter Zhu
array.c:460:14: warning: unused variable 'len' [-Wunused-variable] long len = ARY_HEAP_LEN(ary);
2022-07-21Remove check for shared root arraysPeter Zhu
All shared root arrays should not be on the transient heap. ary_make_shared evacuates arrays from the transient heap when creating shared roots.
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-07-21Add comment in array.c about flagsPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/6157
2022-07-21Add RARRAY_SHARED_FLAGPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/6157
2022-07-21Refactor macros of array.cPeter Zhu
Move some macros in array.c to internal/array.h so that other files can also access these macros. Notes: Merged: https://github.com/ruby/ruby/pull/6157
2022-07-20Add RARRAY_LITERAL_FLAG for array literalsPeter Zhu
Array created as literals during iseq compilation don't need a reference count since they can never be modified. The previous implementation would mutate the hidden array's reference count, causing copy-on-write invalidation. This commit adds a RARRAY_LITERAL_FLAG for arrays created through rb_ary_literal_new. Arrays created with this flag do not have reference count stored and just assume they have infinite number of references. Co-authored-by: Jean Boussier <jean.boussier@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/6151
2022-07-18Remove unused variable in array.cPeter Zhu
vshared is no longer used.
2022-07-12[Feature #18901] Support size pool movement for ArraysMatt Valentine-House
This commit enables Arrays to move between size pools during compaction. This can occur if the array is mutated such that it would fit in a different size pool when embedded. The move is carried out in two stages: 1. The RVALUE is moved to a destination heap during object movement phase of compaction 2. The array data is re-embedded and the original buffer free'd if required. This happens during the update references step Notes: Merged: https://github.com/ruby/ruby/pull/6099
2022-04-28Add missing write barriers to Array#replaceAlan Wu
Previously it made object references without using write barriers, creating GC inconsistencies. See: http://ci.rvm.jp/results/trunk-gc-asserts@phosphorus-docker/3925529 Notes: Merged: https://github.com/ruby/ruby/pull/5851
2022-04-11Correct whitespace in array.c (#5791)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-04-10[DOC] Enhanced RDoc for Array intro (#5781)Burdette Lamar
This covers the first few sections of the class doc for Array. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-03-26[DOC] Use simple references to operator methodsNobuyoshi Nakada
Method references is not only able to be marked up as code, also reflects `--show-hash` option. The bug that prevented the old rdoc from correctly parsing these methods was fixed last month.
2022-03-25Fix formatting errors in What's Here for Array, Hash, ENV (#5718)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-03-25[DOC] Repair format and links in What's Here sections (#5711)Burdette Lamar
* Repair format and links in What's Here for Comparable and Array * Repair format for What's Here in enum.c Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-03-22[Feature #18634] Implement Arrays on Variable Width AllocationPeter Zhu
This commit implements arrays on Variable Width Allocation. This allows longer arrays to be embedded (i.e. contents directly follow the object header) which improves performance through better cache locality. Notes: Merged: https://github.com/ruby/ruby/pull/5660
2022-03-14Assume that refcnt of shared root is non-negativePeter Zhu
The refcnt of a shared root array should always be non-negative.
2022-03-14Assume that shared_root exists in rb_ary_decrement_sharePeter Zhu
All callers of rb_ary_decrement_share guarantee that shared_root is not 0.
2022-03-12Fix crash on GC stress and RGENGC_CHECK_MODE=2Peter Zhu
rb_ary_reset could leave the array in a bad state since it frees memory but does not unset any flags. This can cause a crash on GC stress. This commit changes rb_ary_reset to set the array as an empty embedded array.
2022-03-11Add rb_ary_resetPeter Zhu
rb_ary_reset will free heap allocated arrays and unshare shared arrays.
2022-03-11Refactor duplicate code in rb_array_replacePeter Zhu
In both cases in the if statement, we free heap allocated arrays and unshare shared arrays.
2022-03-07Use rb_ary_unshare for shared array in rb_ary_replacePeter Zhu
rb_ary_unshare will perform FL_UNSET_SHARED and rb_ary_decrement_share.
2022-03-03Doc: fix documentation typo for Array#minRogerio Bordignon
Notes: Merged: https://github.com/ruby/ruby/pull/5621
2022-03-01[DOC] Fix documentation for Array#deleteVivek Bharath Akupatni
Never returns self. Notes: Merged: https://github.com/ruby/ruby/pull/5605 Merged-By: nobu <nobu@ruby-lang.org>
2022-02-23Use rb_ary_behead for rb_ary_shiftPeter Zhu
rb_ary_shift is just a special case of rb_ary_behead where we behead only 1 element. Notes: Merged: https://github.com/ruby/ruby/pull/5590
2022-02-14Use RARRAY_SHARED_ROOT_FLAG for checking re-enterPeter Zhu
RARRAY_SHARED_ROOT_FLAG is defined as FL_USER5, but we should use RARRAY_SHARED_ROOT_FLAG instead of depending on that they're equal. Notes: Merged: https://github.com/ruby/ruby/pull/5547
2022-02-12[DOC] Simplify operator method referencesNobuyoshi Nakada
2022-02-08[DOC] Adjustments to links in array.c (#5532)Burdette Lamar
Mostly suppressing links to itself. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-02-08[DOC] Fix broken links to literals.rdocNobuyoshi Nakada
2022-02-08[DOC] Simplify links to global methodsNobuyoshi Nakada
2022-02-07[DOC] Use RDoc link style for links in the same class/modulePeter Zhu
I used this regex: (?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+) And performed a global find & replace for this: rdoc-ref:$1@$2 Notes: Merged: https://github.com/ruby/ruby/pull/5530
2022-02-07[DOC] Use RDoc link style for links to other classes/modulesPeter Zhu
I used this regex: ([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+) And performed a global find & replace for this: rdoc-ref:$1@$2 Notes: Merged: https://github.com/ruby/ruby/pull/5530
2021-12-03Adding links to literals and Kernel (#5192)Burdette Lamar
* Adding links to literals and Kernel Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-15Use `Primitive.mandatory_only?` for `Array#sample`Koichi Sasada
Notes: Merged: https://github.com/ruby/ruby/pull/5112
2021-11-08[Feature #18290] Remove all usages of rb_gc_force_recyclePeter Zhu
This commit removes usages of rb_gc_force_recycle since it is a burden to maintain and makes changes to the GC difficult. Notes: Merged: https://github.com/ruby/ruby/pull/4363
2021-10-13Remove repeated 'the' (#4966)180909
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2021-10-03Using NIL_P macro instead of `== Qnil`S.H
Notes: Merged: https://github.com/ruby/ruby/pull/4925 Merged-By: nobu <nobu@ruby-lang.org>
2021-09-15[DOC] Fix broken links [ci skip]Nobuyoshi Nakada
* As the "doc/" prefix is specified by the `--page-dir` option, remove from the rdoc references. * Refer to the original .rdoc instead of the converted .html.
2021-09-14Bsearch doc for Array and Range (#4838)Burdette Lamar
This PR creates doc/bsearch.rdoc to provide common documentation for bsearch in Array and Range. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-11Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4805
2021-09-10include/ruby/internal/intern/array.h: add doxygen卜部昌平
Must not be a bad idea to improve documents. [ci skip] Notes: Merged: https://github.com/ruby/ruby/pull/4815
2021-09-02Guard array when appendingAaron Patterson
This prevents early collection of the array. The GC doesn't see the array on the stack when Ruby is compiled with optimizations enabled [ruby-core:105099] [Bug #18140]
2021-08-31Fix a code in the Array#min documentation.universato
Notes: Merged: https://github.com/ruby/ruby/pull/4463
2021-08-29Fix length calculation for Array#slice!Mike Dalessio
Commit 4f24255 introduced a bug which allows a length to be passed to rb_ary_new4 which is too large, resulting in invalid memory access. For example: (1..1000).to_a.slice!(-2, 1000) Notes: Merged: https://github.com/ruby/ruby/pull/4787