aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
Commit message (Collapse)AuthorAgeFilesLines
* make functions static卜部昌平2019-11-191-0/+2
| | | | | | | These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-11/+0
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Prefer st_is_member over st_lookup with 0Ben Woosley2019-10-091-1/+1
| | | | The st_is_member DEFINE has simpler semantics, for more readable code.
* Improve performance of Array#sum with float elements (#1555)Watson2019-10-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The declaration of local variable in loop, it will initialize local variable for each run of the loop with clang generated code. So, it shouldn't declare the local variable in heavy loop. Array#sum with float elements will be faster around 30%. * Before user system total real 3.320000 0.010000 3.330000 ( 3.336088) * After user system total real 2.590000 0.010000 2.600000 ( 2.602399) * Test code require 'benchmark' Benchmark.bmbm do |x| ary = [] 10000.times { ary << Random.rand } x.report do 50000.times do ary.sum end end end
* Add: Array#intersection methodPrajjwal Singh2019-10-071-0/+31
|
* array.c (rb_mem_clear): remove "register" from argumentsYusuke Endoh2019-10-041-1/+1
| | | | | | | | | | | | | | | | to suppress the following warning: ``` compiling cxxanyargs.cpp In file included from cxxanyargs.cpp:1: In file included from ../../.././include/ruby/ruby.h:2150: ../../.././include/ruby/intern.h:56:19: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register] void rb_mem_clear(register VALUE*, register long); ^~~~~~~~~ ../../.././include/ruby/intern.h:56:36: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register] void rb_mem_clear(register VALUE*, register long); ^~~~~~~~~ ```
* [DOC] Fix typos in Array#{to_s,inspect} doc [ci skip]Benoit Daloze2019-09-291-1/+1
|
* [DOC] stated that Array#to_s calls #inspect [ci skip]Nobuyoshi Nakada2019-09-291-1/+2
| | | | [ruby-list:50826]
* Optimize Array#flatten and flatten! for already flattened arrays (#2495)Dylan Thacker-Smith2019-09-281-10/+33
| | | | | | | * Optimize Array#flatten and flatten! for already flattened arrays * Add benchmark for Array#flatten and Array#flatten! [Bug #16119]
* check `ARY_SHARED_ROOT_P()`.Koichi Sasada2019-09-251-1/+5
| | | | | ARY_SHARED_ROOT_P(ary) is true, ARY_HEAP_CAPA(ary) should not be called.
* introduce `obj_ary_extracapa`.Koichi Sasada2019-09-251-0/+2
| | | | | Introduce a new debug counter `obj_ary_extracapa` which counts arrays which are `len < capa`.
* Fixed memory leakNobuyoshi Nakada2019-09-201-3/+8
| | | | | * array.c (flatten): fix a memory leak in the case of an exception at conversion of an element to Array.
* Fix typosKenichi Kamiya2019-09-181-5/+5
|
* Make Array#uniq return subclass instance if called on subclass instanceJeremy Evans2019-09-021-4/+8
| | | | | | | | Previously, Array#uniq would return subclass instance if the length of the array were 2 or greater, and would return Array instance if the length of the array were 0 or 1. Fixes [Bug #7768]
* Avoid confusion in Array#- and Array#difference docs (#2070)Olivier Lacan2019-08-161-6/+6
| | | | | | My previous attempt to correct #2068 apparently failed and the confusing wording ("instances") was merged into trunk instead. This should address any potential confusion.
* Allow Array#join to allocate smaller stringsJohn Hawthorn2019-08-091-1/+3
| | | | | | | | | | | | | | rb_str_buf_new always allocates at least 127 bytes of capacity, even when less is requested. > ObjectSpace.dump(%w[a b c].join) {"address":"0x7f935f06ebf0", "type":"STRING", "class":"0x7f935d8b7bb0", "bytesize":3, "capacity":127, "value":"abc", "encoding":"UTF-8", "memsize":168, "flags":{"wb_protected":true}} Instead, by using rb_str_new and then setting the length to 0, we can allocate the exact amount of memory needed, without extra capacity. > ObjectSpace.dump(%w[a b c].join) {"address":"0x7f903fcab530", "type":"STRING", "class":"0x7f903f8b7988", "embedded":true, "bytesize":3, "value":"abc", "encoding":"UTF-8", "memsize":40, "flags":{"wb_protected":true}}
* array.c: gc.h is not neededYusuke Endoh2019-08-071-1/+0
|
* [Doc] Fix Array#to_h call-seqKenichi Kamiya2019-08-041-2/+2
| | | | Closes: https://github.com/ruby/ruby/pull/2254
* [Doc] Fix Array#difference call-seqKenichi Kamiya2019-08-041-1/+1
| | | | Closes: https://github.com/ruby/ruby/pull/2255
* array.c: factor out a complex condition of assertYusuke Endoh2019-07-201-2/+8
| | | | | | | | | | | ARY_SHARED_P and ARY_EMBED_P included: assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), The two predicate macros are used in many other assert conditions, which caused memory bloat during C compilation. This change factors out the assertion above to a function. Now gcc consumes 160 MB instead of 250 MB to compile array.c.
* array.c: use assert in macro instead of in a functionYusuke Endoh2019-07-191-7/+7
| | | | | The old code lost information of lineno. Now, an assertion error will output a correct lineno (but now gcc 8 requires 250 MB, unfortunately).
* array.c: factor out `assert(RB_TYPE_P(ary, T_ARRAY))` to a functionYusuke Endoh2019-07-191-4/+10
| | | | | | | The assertion blows up gcc 8 by consuming approx. 1.8 GB memory. This change reduces the amount of memory required to about 200 MB. A follow-up of ae750799c1b28b06d02e50cd26450b9903516526.
* Use FL_TEST_RAW() to check flags.Koichi Sasada2019-07-191-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | FL_TEST() uses FL_ABLE() which test data types. However, in array.c we don't need to check it (all of them should be T_ARRAY), so I changed from FL_TEST() to FL_TEST_RAW() which does not check FL_ABLE(). Instead of FL_ABLE(), add assertion to check given object is a T_ARRAY object. For example, rb_ary_free() becomes slim: with FL_TEST(): 0000000000006a30 <rb_ary_free>: 6a30: 40 f6 c7 07 test $0x7,%dil 6a34: 48 8b 07 mov (%rdi),%rax 6a37: 75 09 jne 6a42 <rb_ary_free+0x12> 6a39: 48 f7 c7 f7 ff ff ff test $0xfffffffffffffff7,%rdi 6a40: 75 1e jne 6a60 <rb_ary_free+0x30> 6a42: a9 00 00 00 02 test $0x2000000,%eax 6a47: 74 07 je 6a50 <rb_ary_free+0x20> 6a49: f3 c3 repz retq 6a4b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 6a50: 48 8b 7f 20 mov 0x20(%rdi),%rdi 6a54: e9 00 00 00 00 jmpq 6a59 <rb_ary_free+0x29> 6a59: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 6a60: 89 c2 mov %eax,%edx 6a62: 83 e2 1f and $0x1f,%edx 6a65: 83 fa 1b cmp $0x1b,%edx 6a68: 74 d8 je 6a42 <rb_ary_free+0x12> 6a6a: f6 c4 60 test $0x60,%ah 6a6d: 74 d3 je 6a42 <rb_ary_free+0x12> 6a6f: eb d8 jmp 6a49 <rb_ary_free+0x19>``` with FL_TEST_RAW(): 0000000000006a30 <rb_ary_free>: 6a30: 48 f7 07 00 60 00 02 testq $0x2006000,(%rdi) 6a37: 74 07 je 6a40 <rb_ary_free+0x10> 6a39: f3 c3 repz retq 6a3b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 6a40: 48 8b 7f 20 mov 0x20(%rdi),%rdi 6a44: e9 00 00 00 00 jmpq 6a49 <rb_ary_free+0x19>
* * expand tabs.git2019-07-191-19/+19
|
* fix shared array terminology.Koichi Sasada2019-07-191-53/+62
| | | | | | | | | | | | | | | | | | Shared arrays created by Array#dup and so on points a shared_root object to manage lifetime of Array buffer. However, sometimes shared_root is called only shared so it is confusing. So I fixed these wording "shared" to "shared_root". * RArray::heap::aux::shared -> RArray::heap::aux::shared_root * ARY_SHARED() -> ARY_SHARED_ROOT() * ARY_SHARED_NUM() -> ARY_SHARED_ROOT_REFCNT() Also, add some debug_counters to count shared array objects. * ary_shared_create: shared ary by Array#dup and so on. * ary_shared: finished in shard. * ary_shared_root_occupied: shared_root but has only 1 refcnt. The number (ary_shared - ary_shared_root_occupied) is meaningful.
* introduce RUBY_ASSERT_ALWAYS(expr).Koichi Sasada2019-07-151-1/+1
| | | | | RUBY_ASSERT_ALWAYS(expr) ignores NDEBUG (we cannot remove this assertion).
* Implement Array#minmaxJeremy Evans2019-07-021-0/+21
| | | | | | | | | Array#minmax was previous not implemented, so calling #minmax on array was actually calling Enumerable#minmax. This is a simple implementation of #minmax by just calling rb_ary_min and rb_ary_max, which improves performance significantly. Fixes [Bug #15929]
* array.c: Wrong heap size given to ruby_sized_xfree when freeing shared rootsLuke Gruber2019-06-241-2/+2
| | | | | | Fixes [Bug #15953] Closes: https://github.com/ruby/ruby/pull/2253
* array.c add back shared array optimization to ary_ensure_room_for_unshiftLuke Gruber2019-06-231-2/+2
| | | | | | | Bug fix in commit ec8e5f5aa64e2a [Bug #15952] disabled an optimization in this function. Closes: https://github.com/ruby/ruby/pull/2252
* array.c: always check frozenness in Array#unshift. Fixes [Bug #15952]Luke Gruber2019-06-231-1/+2
| | | | Closes: https://github.com/ruby/ruby/pull/2251
* Fix issue with Array#rindex when rb_equal modifies receiver arrayLuke Gruber2019-06-231-0/+3
| | | | | | Fixes [Bug #15951] Closes: https://github.com/ruby/ruby/pull/2250
* add comments to mention sort.reverse!Martin Dürst2019-06-131-0/+5
| | | | | | For array.c (Array#sort) and enum.c (Enumerable#sort_by), add comments mentioning that sort.reverse! / sort_by { ... }.reverse! can/should be used to reverse the result. [ci skip]
* do not use RARRAY_SET() directly in array.c.Koichi Sasada2019-05-211-2/+10
|
* Improve documentation of Array.try_convertBenoit Daloze2019-04-271-2/+2
| | | | * Mostly to try the new git repository.
* Merge branch 'patch-5' of https://github.com/sos4nt/ruby into trunkKazuhiro NISHIYAMA2019-04-221-1/+1
|\ | | | | | | [Fix GH-2084]
| * Fix return value name in docs for Array#unionStefan Schüßler2019-02-181-1/+1
| | | | | | Throughout the docs, `new_ary` is used to indicate a new array, whereas `ary` refers to the receiver.
* | io.c: warn non-nil $,nobu2019-04-181-4/+4
| | | | | | | | | | | | | | | | * array.c (rb_ary_join_m): warn use of non-nil $,. * io.c (rb_output_fs_setter): warn when set to non-nil value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Introduce pattern matching [EXPERIMENTAL]ktsj2019-04-171-0/+8
| | | | | | | | | | | | [ruby-core:87945] [Feature #14912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Adjusted stylesnobu2019-04-101-1/+1
| | | | | | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Reverting all commits from r67479 to r67496 because of CI failureskazu2019-04-101-1/+1
| | | | | | | | | | | | | | | | Because hard to specify commits related to r67479 only. So please commit again. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Adjusted stylesnobu2019-04-101-1/+1
| | | | | | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Fix a typo [ci skip]kazu2019-03-311-1/+1
| | | | | | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | array.c: [DOC] remove unnecessary markups [ci skip]nobu2019-03-211-2/+2
|/ | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Clarify Array#- and Array#difference documentationnobu2019-01-151-6/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently we are not explicit enough regarding the potentially confusing behavior of `Array#-` and `Array#difference` when it comes to duplicate items within receiver arrays. Although the original documentation for these methods does use an array with multiple instance of the same integers, the explanation for the behavior is actually imprecise. > removing any items that also appear in +other_ary+ Not only does `Array#-` remove any items that also appear in `other_ary` but it also remove any instance of any item in `other_ary`. One may expect `Array#-` to behave like mathematical subtraction or difference when it doesn't. One could be forgiven to expect the following behavior: ```ruby [1,1,2,2,3,3,4,4] - [1,2,3,4] => [1,2,3,4] ``` In reality this is the result: ```ruby [1,1,2,2,3,3,4,4] - [1,2,3,4] => [] ``` I hope that I've prevented this potential confusion with the clarifications in this change. I can offer this as evidence of likeliness for confusion: https://twitter.com/olivierlacan/status/1084930269533085696 I'll freely admit I was surprised by this behavior myself since I needed to obtain an Array with only one instance of each item in the argument array removed. [Fix GH-2068] [ci skip] From: Olivier Lacan <hi@olivierlacan.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix styles [ci skip]nobu2019-01-091-3/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Mark array as "going to be modified" in `Array#reject!`tenderlove2019-01-081-0/+1
| | | | | | | | | | | Before this patch, if `reject!` is called on a shared array it can mutate the shared array rather than a copy. This patch marks the array as "going to be modified" so that the shared source array isn't mutated. [Bug #15479] [ruby-core:90781] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix marking T_NONE object bug.ko12018-12-231-1/+7
| | | | | | | | | | | * array.c (rb_ary_splice): do not use RARRAY_PTR() here because it can cause GC because of rb_ary_detransient(). Here ary can contain T_NONE object because of increasing capacity and not initialized yet. error log: http://ci.rvm.jp/results/trunk-test@ruby-sky1/1557174 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rename li_table->ar_table (and related names).ko12018-12-141-2/+2
| | | | | | | | | | | | | | | | | | | * internal.h: rename the following names: * li_table -> ar_table. "li" means linear (from linear search), but we use the word "array" (from data layout). * RHASH_ARRAY -> RHASH_AR_TABLE. AR_TABLE is more clear. * rb_hash_array_* -> rb_hash_ar_table_*. * RHASH_TABLE_P() -> RHASH_ST_TABLE_P(). more clear. * RHASH_CLEAR() -> RHASH_ST_CLEAR(). * hash.c: rename "linear_" prefix functions to "ar_" prefix. * hash.c (linear_init_table): rename to ar_alloc_table. * debug_counter.h: rename obj_hash_array to obj_hash_ar. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* implement Array-specific #all?, #none?, #one?nobu2018-12-051-0/+121
| | | | | | | | | | | | | | | Before this patch Array#all? was not implemented in Array class and alternatively Enumerable#all? was used, while #any? has its own method entry in Array class. Similarly, Array#none? and #one? also lacks its own implementation. This patch provides Array-specific implementations for above three methods to enable faster method lookup. [Fix GH-2041] From: Koji Onishi <fursich0@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Prefer rb_check_arity when 0 or 1 argumentsnobu2018-12-051-31/+26
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e