summaryrefslogtreecommitdiff
path: root/array.c
AgeCommit message (Collapse)Author
2017-02-18array.c: check if numericnobu
* array.c (finish_exact_sum): add 0 and the initial value to check if the latter is numeric. [ruby-core:79572] [Bug #13222] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-18array.c: finish_exact_sumnobu
* array.c (finish_exact_sum): extract duplicate code from rb_ary_sum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-13array.c (ary_recycle_hash): use rb_gc_force_recyclenormal
Hidden objects (RBASIC_CLASS(hash) == 0) can never become visible to other threads or signal handlers via ObjectSpace.each_object or similar means. Thus it is safe to forcibly recycle the object slot for future use, here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-20array.c: improve Array#samplenobu
* array.c (rb_ary_sample): improve performance when many samples from a large array. based on the patch by tomoya ishida <tomoyapenguin AT gmail.com> in [ruby-dev:49956]. [Bug #13136] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-14mention behavior of Array#join for nested arrays [ci skip]normal
The current documentation for Array#join does not mention the special treatment of nested arrays. It says: > Returns a string created by converting each element of the > array to a string, separated by the given separator. Expected behavior according to the docs would be: [ "a", [1, 2, [:x, :y]], "b" ].join("-") #=> "a-[1, 2, [:x, :y]]-b" # because of: [1, 2, [:x, :y]].to_s #=> "[1, 2, [:x, :y]]" Actual behavior: [ "a", [1, 2, [:x, :y]], "b" ].join("-") #=> "a-1-2-x-y-b" because join is applied recursively for nested arrays. The patch clarifies this behavior. (Also: small markup and grammar fix.) Patch by Marcus Stollsteimer <sto.mar@web.de> [ruby-talk:437238] [ruby-core:79079] [Bug #13130] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20array.c: do not resize to less than 0rhe
Shrinking the Array from the block invoked by Array#select! or Array#reject! causes the Array to be a negative number size. Ensure that the resulting Array won't be smaller than 0. [ruby-core:78739] [Bug #13053] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20array.c: check array length every time after yieldingrhe
Since the Array may be modified during rb_yield(), the length before invoking the block can't be trusted. Fix possible out-of-bounds read in Array#combination and Array#repeated_combination. It may better to make a defensive copy of the Array, but for now let's follow what Array#permutation does. [ruby-core:78738] [Bug #13052] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57119 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-11-08Update documentation of fetcha_matsuda
The sentence `Negative values of +index+ count from the end of the array.` can be interpreted that it only holds if a block is given. Clarify it. Patch by: Lukas Elmer <lukas.elmer@gmail.com> (@lukaselmer) Signed-off-by: Akira Matsuda <ronnie@dio.jp> closes #1472 [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05[DOC] add explanation for Array#sumakr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56566 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-09replace Fixnum with Integer in rdoc [ci skip]nobu
* array.c, class.c: Fixed documentation where Fixnum was referred directly to use Integer, as Fixnum and Bignum are now unified into Integer and direct usage is deprecated. [Fix GH-1459] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-04* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.usa
a hash value of Object might be Bignum, but it causes many troubles expecially the Object is used as a key of a hash. so I've gave up to do so. * array.c (rb_ary_hash): use above macro. * bignum.c (rb_big_hash): ditto. * hash.c (rb_obj_hash, rb_hash_hash): ditto. * numeric.c (rb_dbl_hash): ditto. * proc.c (proc_hash): ditto. * re.c (rb_reg_hash, match_hash): ditto. * string.c (rb_str_hash_m): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-04array.c: update Array#dig docnobu
* array.c (rb_ary_dig): [DOC] update an example of error message by Array#dig, because of Integer Unification. [Fix GH-1455] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56337 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-09-08* array.c (flatten): use rb_obj_class instead of rb_class_ofktsj
because rb_class_of may return a singleton class. [ruby-dev:49781] [Bug #12738] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08replace fixnum by integer in documents.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-27multiple argumentsnobu
* array.c (rb_ary_concat_multi): take multiple arguments. based on the patch by Satoru Horie. [Feature #12333] * string.c (rb_str_concat_multi, rb_str_prepend_multi): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-22array.c: elements in selfnobu
* array.c (rb_ary_splice): consider elements in middle of self. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-21array.c: no temporary arraynobu
* array.c (rb_ary_splice): use pointer and length pair instead of an array object to replace. * array.c (rb_ary_insert): get rid of creating temporary array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-20hash.c: rb_hash_add_new_elementnobu
* hash.c (rb_hash_add_new_element): add new element or do nothing if it is contained already. * array.c (ary_add_hash, ary_add_hash_by): use rb_hash_add_new_element. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-23* array.c (rb_ary_fill): suppress warnings: 'item' may be usednaruse
uninitialized in this function git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-15* array.c (rb_ary_entry): extract rb_ary_elt to organize if-conditionsnaruse
and check whether is is embdeded at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-01Fix rb_ary_sum for mathnmrkn
* array.c (rb_ary_sum): fix for mathn * test/ruby/test_array.rb (test_sum): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22[DOC] Arrah#sum with non-numeric objects.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-17* array.c (rb_ary_sum): [DOC] fix typos.ktsj
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15* array.c (rb_ary_sum): Don't yield same element twice.akr
Found by nagachika. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15* array.c (rb_ary_sum): Fix SEGV by [1/2r, 1].sum.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15rename rb_rational_add -> rb_rational_plusmrkn
* rational.c (rb_rational_plus): rename from rb_rational_add to be aligned with rb_fix_plus. * array.c (rb_ary_sum): ditto. * internal.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15array.c (rb_ary_sum): use rb_rational_add directlymrkn
* rational.c (rb_rational_add): rename from nurat_add. * array.c (rb_ary_sum): use rb_rational_add directly. * test/ruby/test_array.rb (test_sum): add assertions for an array of Rational values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-15array.c: sum for Rational and Float mixed arraysmrkn
* array.c (rb_ary_sum): apply the precision compensated algorithm for an array in which Rational and Float values are mixed. * test/ruby/test_array.rb (test_sum): add assertions for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-14[DOC]akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-14* array.c (rb_ary_sum): Support the optional argument, init, and block.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-14[DOC]akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13* array.c (rb_ary_sum): Array#sum is implemented.akr
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
2016-03-17* array.c, enum.c: make rdoc format consistent.mame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17* array.c (rb_ary_max, rb_ary_min): implement Array#max and min withmame
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
2016-03-17* array.c (rb_ary_max, rb_ary_min): implement a block by itself insteadmame
of delegating Enumerable#max/min. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17* array.c (rb_ary_max, rb_ary_min): Array#max and Array#min added.mame
[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
2016-03-17* internal.c: struct cmp_opt_data added for refactoring out a datamame
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
2016-02-29array.c: [DOC] remove trailing comma [ci skip]nobu
* array.c (rb_ary_push_m): [DOC] Remove trailing comma from Array#push example, as other Array examples doesn't put trailing comma. [Fix GH-1279] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-28Clarify set intersection and union documentationnobu
* array.c (rb_ary_and): clarify that set intersection returns the unique elements common to both arrays. * array.c (rb_ary_or): clarify that union preserves the order from the given arrays. - Most know what intersection means, but saying the operation excludes duplicates could be misleading ([1] & [1], duplicates excluded, might mean a result of []). - Instead, saying intersection returns the unique elements common to both arrays is more concise and less ambiguous. - The set union's documentation was incomplete in its describing preservation of order. Saying union preserves the order of the original array neglects the idea that the order of the elements in both arrays, as given, will be preserved. - Instead, saying set union preserves the order from the given arrays (and adding an example) fully demonstrates the idea. [Fix GH-1273] [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-27Fix a Ruby-Doc comment for Array#dignobu
* array.c (rb_ary_dig): [DOC] fix the exception class to be raised when intermediate object does not have dig method. TypeError will be raised now. [Fix GH-1224] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-26array.c: reword [ci skip]nobu
* array.c (permute0, rpermute0): [DOC] Substitute indexes -> indices in documentation for consistency. [Fix GH-1222] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-22RUBY_ASSERTnobu
* error.c (rb_assert_failure): assertion with stack dump. * ruby_assert.h (RUBY_ASSERT): new header for the assertion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-07* enum.c (enum_minmax): optimize object comparison inshugo
Enumerable#minmax. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08* array.c: Improve and fix documentation for Array#digmarcandre
[#11776] * hash.c: ditto * struct.c: ditto * test_hash.rb: Add basic test for user defined `dig`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-20* array.c: clarify docs for take_while/drop_while samples.hsbt
[ci skip][fix GH-1028] Patch by @leriksen git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17update rdoc of dig methods [ci skip]nobu
* array.c (rb_ary_dig), hash.c (rb_hash_dig): [DOC] Update comments describing dig methods. [Fix GH-1103] * struct.c (rb_struct_dig): [DOC] add rdoc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-09dignobu
* array.c (rb_ary_dig): new method Array#dig. * hash.c (rb_hash_dig): new method Hash#dig. * object.c (rb_obj_dig): dig in nested arrays/hashes. [Feature #11643] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e