summaryrefslogtreecommitdiff
path: root/test/ruby/test_hash.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add documentation and tests for keyword argument value omissionShugo Maeda2021-09-111-18/+0
| | | | [Feature #14579]
* Another test for [Feature #14579]Nobuyoshi Nakada2021-09-111-0/+1
| | | | The value of the dynamic key cannot be omitted for now.
* Allow value omission in Hash literalsShugo Maeda2021-09-111-0/+17
| | | | `{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
* Free previously used tables [Bug #18134]Nobuyoshi Nakada2021-08-291-0/+9
|
* Remove old warning aged nearly 8 yearsNobuyoshi Nakada2021-08-191-9/+0
|
* Copy hash compare_by_identity setting in more casesJeremy Evans2021-07-151-0/+169
| | | | | | | | | | | | | | | | | | This makes the compare_by_identity setting always copied for the following methods: * except * merge * reject * select * slice * transform_values Some of these methods did not copy the setting, or only copied the setting if the receiver was not empty. Fixes [Bug #17757] Co-authored-by: Kenichi Kamiya <kachick1@gmail.com>
* Split test of Hash.[] and add assertion for default value/procNobuyoshi Nakada2021-07-081-1/+11
| | | | For a73f13c9070a5189947641638398cbffb8d012d8.
* Keep non evaluated keys in `Hash#transform_keys!` [Bug #17735]Kenichi Kamiya2021-03-281-0/+8
|
* Hash#transform_values! ensures receiver modifiable in block [Bug #17736]Kenichi Kamiya2021-03-221-0/+9
|
* Ensure the receiver hash modifiable before updating [Bug #17736]Nobuyoshi Nakada2021-03-211-0/+12
| | | | Close https://github.com/ruby/ruby/pull/4298
* Add Hash#{update, merge!} test to ensure receiver modifiable in blockKenichi Kamiya2021-03-211-0/+16
|
* Some Hash destructive methods ensure the receiver modifiable [Bug #17736]Kenichi Kamiya2021-03-201-0/+42
| | | | | | | | | | | | | | | | | | | | | | refs: * https://bugs.ruby-lang.org/issues/17736 * https://github.com/ruby/ruby/pull/4296 This commit aims to cover following methods * Hash#select! * Hash#filter! * Hash#keep_if * Hash#reject! * Hash#delete_if I think these are not all. --- * Ensure the receiver is modifiable or not * Assert the receiver is not modified
* Avoid rehashing in Hash#replace/dup/initialize_copy [Bug #16996]Marc-Andre Lafortune2021-03-181-7/+3
|
* Avoid rehashing in Hash#select/reject [Bug #16996]Marc-Andre Lafortune2021-03-181-0/+25
|
* Make any hash values fixable [Bug #17488]Nobuyoshi Nakada2020-12-311-0/+26
| | | | | | | As hnum is an unsigned st_index_t, the result of RSHIFT may not be in the fixable range. Co-authored-by: NeoCat <neocat@neocat.jp>
* test/ruby: suppress some warningsYusuke Endoh2020-12-171-1/+7
| | | | follow up to 9908177857a28633d6279c43a1ad4dfedcb98596
* test/ruby: Check warning messages at a finer granularityNobuyoshi Nakada2020-12-171-2/+3
| | | | | Instead of suppressing all warnings wholly in each test scripts by setting `$VERBOSE` to `nil` in `setup` methods.
* Make hash returned by Hash#transform_values not have a defaultJeremy Evans2020-09-211-0/+1
| | | | | | | This sets an explicit default of nil. There is probably a better approach of removing the default. Fixes [Bug #17181]
* Add Hash#except ENV#except [Feature #15822]Timo Schilling2020-06-181-0/+8
|
* `Proc` made by `Hash#to_proc` should be a lambda [Bug #12671]Yusuke Endoh2020-03-161-0/+2
| | | | Like `Symbol#to_proc` (f0b815dc670b61eba1daaa67a8613ac431d32b16)
* hash.c: Do not use the fast path (rb_yield_values) for lambda blocksYusuke Endoh2020-03-161-0/+6
| | | | | | | | | | | | | | | | | As a semantics, Hash#each yields a 2-element array (pairs of keys and values). So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception due to lambda's arity check. However, the optimization that avoids Array allocation by using rb_yield_values for blocks whose arity is more than 1 (introduced at b9d29603375d17c3d1d609d9662f50beaec61fa1 and some commits), seemed to overlook the lambda case, and wrongly allowed the code above to work. This change experimentally attempts to make it strict; now the code above raises an ArgumentError. This is an incompatible change; if the compatibility issue is bigger than our expectation, it may be reverted (until Ruby 3.0 release). [Bug #12706]
* check ar_table after `#hash` callKoichi Sasada2020-03-071-0/+58
| | | | | | | ar_table can be converted to st_table just after `ar_do_hash()` function which calls `#hash` method. We need to check the representation to detect this mutation. [Bug #16676]
* should count only string.Koichi Sasada2020-02-251-2/+5
| | | | | This code can generate CC objects so we only need to count existing String objects.
* Fix typo s/test_ruby2_keywords_hash!/test_ruby2_keywords_hash/Ryuta Kamizono2020-01-191-1/+1
| | | In #2818, `Hash.ruby2_keywords!` has renamed to `Hash.ruby2_keywords_hash`.
* hash.c: Add a feature to manipulate ruby2_keywords flagYusuke Endoh2020-01-171-0/+24
| | | | | | | | | | | | | | | It was found that a feature to check and add ruby2_keywords flag to an existing Hash is needed when arguments are serialized and deserialized. It is possible to do the same without explicit APIs, but it would be good to provide them as a core feature. https://github.com/rails/rails/pull/38105#discussion_r361863767 Hash.ruby2_keywords_hash?(hash) checks if hash is flagged or not. Hash.ruby2_keywords_hash(hash) returns a duplicated hash that has a ruby2_keywords flag, [Bug #16486]
* Hash#transform_values should return a plain new HashNobuyoshi Nakada2020-01-101-0/+6
| | | | [Bug #16498]
* Transform hash keys by a hash [Feature #16274]Nobuyoshi Nakada2019-12-261-0/+10
|
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-46/+16
| | | | | | 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.
* check hash_hint is different.Koichi Sasada2019-08-011-1/+10
|
* test/ruby/test_hash.rb: remove a unused vribleYusuke Endoh2019-07-311-1/+1
| | | | to suppress a warning
* check SystemStackErrorKoichi Sasada2019-07-311-6/+10
| | | | | This recursive iteration test can cause SystemStackError so check it correctly.
* remove RHash::iter_lev.Koichi Sasada2019-07-311-0/+25
| | | | | | | | | | | | | | | iter_lev is used to detect the hash is iterating or not. Usually, iter_lev should be very small number (1 or 2) so `int` is overkill. This patch introduce iter_lev in flags (7 bits, FL13 to FL19) and if iter_lev exceeds this range, save it in hidden attribute. We can get 1 word in RHash. We can't modify frozen objects. Therefore I added new internal API `rb_ivar_set_internal()` which allows us to set an attribute even if the target object is frozen if the name is hidden ivar (the name without `@` prefix).
* hash.c (rb_hash_s_create): Reject `Hash[[nil]]`Yusuke Endoh2019-05-231-6/+5
| | | | | | | The behavior of `Hash[[nil]] #=> {}` was a bug until 1.9.3, but had been remained with a warning because some programs depended upon it. Now, six years passed. We can remove the compatibility behavior. [Bug #7300]
* Adjust reserved hash valuesnobu2018-12-071-0/+9
| | | | | | | The reserved hash values in hash.c must be consistend with st.c. [ruby-core:90356] [Bug #15389] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* clear dst Hash on Hash#replace. [Bug #15358]ko12018-11-291-0/+8
| | | | | | | | | | | | * hash.c (linear_copy): solve two issues on `Hash#replace`. (1) fix memory leak (1-1) don't allocate memory if destination already has a memory area. (1-2) free destination memory if src is NULL. (2) clear transient heap flag if src is NULL. [Bug #15358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: aset deduplicates un-tainted stringnormal2018-10-261-0/+18
| | | | | | | | | | | | We revisit [Bug #9188] since st.c is much improved since then, and benchmarks against so_k_nucleotide seem to indicate little or no performance change compared to before. [ruby-core:89555] [Feature #15251] From: Anmol Chopra <chopraanmol1@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Enumerable#to_h with block and so onnobu2018-09-201-0/+10
| | | | | | [Feature #15143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c (rb_hash_merge): Accepts zero or more hashes as argumentsmame2018-09-191-0/+24
| | | | | | | | | | | | Hash#merge, merge!, and update could merge exactly two hashes. Now, they accepts zero or more hashes as arguments so that it can merge hashes more than two. This patch was created by Koki Ryu <liukoki@gmail.com> at Ruby Hack Challenge #5. Thank you! [ruby-core:88970] [Feature #15111] [Fix GH-1951] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a new #filter alias for #selecteregon2018-02-251-0/+38
| | | | | | | | | | | | | | | * 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
* hash.c: support key swapping in Hash#transform_keys!mrkn2018-01-261-0/+8
| | | | | | | | | | | * hash.c (rb_hash_transform_keys_bang): support key swapping in Hash#transform_keys! [Bug #14380] [ruby-core:84951] * test/ruby/test_hash.rb (test_transform_keys_bang): add assertions for this change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash literal deduplicates like Hash#[]=normal2017-12-301-0/+3
| | | | | | | | | | | | | From: Eric Wong <e@80x24.org> * hash.c (rb_hash_key_str): new function (hash_aset_str): use rb_hash_key_str * internal.h: add rb_hash_key_str * st.c (st_stringify): use rb_hash_key_str * test/ruby/test_hash.rb (test_NEWHASH_fstring_key): dynamic key [ruby-core:84554] [Feature #14258] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby/test_hash: minor test cleanupnormal2017-12-291-4/+4
| | | | | | | | | Prep work for proposed behavior change: https://bugs.ruby-lang.org/issues/14225 * test/ruby/test_hash.rb (test_tainted_string_key): assert_predicate git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* force hash values fixableusa2017-12-221-0/+7
| | | | | | | | | | * include/ruby/ruby.h (RB_ST2FIX): force fixable on LLP64 environment. * hash.c (any_hash): ditto. [ruby-core:84395] [Bug #14218] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add FrozenError as a subclass of RuntimeErrorshyouhei2017-12-121-2/+2
| | | | | | | | | | | | | | FrozenError will be used instead of RuntimeError for exceptions raised when there is an attempt to modify a frozen object. The reason for this change is to differentiate exceptions related to frozen objects from generic exceptions such as those generated by Kernel#raise without an exception class. From: Jeremy Evans <code@jeremyevans.net> Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add arity check into Hash#flattenglass2017-10-221-1/+6
| | | | | | * hash.c (rb_hash_flatten): add arity check git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: Add Hash#sliceglass2017-10-211-0/+8
| | | | | | * hash.c (rb_hash_slice): add Hash#slice [Feature #8499] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* error.c: KeyError#receiver and KeyError#keynobu2017-09-181-1/+5
| | | | | | | | | | | | | * error.c: new method KeyError#receiver and KeyError#key. [Feature #12063] * hash.c: make KeyError object with receiver and key. * sprintf.c: ditto. Author: ksss <co000ri@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: Add Hash#transform_keys and Hash#transform_keys!mrkn2017-07-141-0/+28
| | | | | | | | | | | | * hash.c (transform_keys_i, rb_hash_transform_keys): Add Hash#transform_keys. [Feature #13583] [ruby-core:81290] * hash.c (rb_hash_transform_keys_bang): Add Hash#transform_keys!. [Feature #13583] [ruby-core:81290] * test/ruby/test_hash.rb: Add tests for above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* tainted string should be tainted.ko12017-07-111-0/+11
| | | | | | | | * hash.c (hash_aset_str): create frozen string for tainted objects. (should not use fsting table on this case). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* refactor newhash (revision 58463 another try) [fix GH-1600]shyouhei2017-04-271-1/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * st.c (rb_hash_bulk_insert): new API to bulk insert entries into a hash. Given arguments are first inserted into the table at once, then reindexed. This is faster than inserting things using rb_hash_aset() one by one. This arrangement (rb_ prefixed function placed in st.c) is unavoidable because it both touches table internal and write barrier at once. * internal.h: delcare the new function. * hash.c (rb_hash_s_create): use the new function. * vm.c (core_hash_merge): ditto. * insns.def (newhash): ditto. * test/ruby/test_hash.rb: more coverage on hash creation. * test/ruby/test_literal.rb: ditto. ----------------------------------------------------------- benchmark results: minimum results in each 7 measurements. Execution time (sec) name before after loop_whileloop2 0.136 0.137 vm2_bighash* 1.249 0.623 Speedup ratio: compare with the result of `before' (greater is better) name after loop_whileloop2 0.996 vm2_bighash* 2.004 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e