summaryrefslogtreecommitdiff
path: root/hash.c
AgeCommit message (Collapse)Author
2023-06-01[DOC] Mention the edge case of `any?`/`all?`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7883
2023-05-23Remove dead code in rb_hash_replacePeter Zhu
We now always copy the ST table, so we don't need to initialize the ST table of hash when hash2 is empty. Notes: Merged: https://github.com/ruby/ruby/pull/7846
2023-05-23Fix crash when replacing ST hash with AR hashPeter Zhu
With VWA, AR hashes are much larger than ST hashes. Hash#replace attempts to directly copy the contents of AR hashes into ST hashes so there will be memory corruption caused by writing past the end of memory. This commit changes it so that if a ST hash is being replaced with an AR hash it will insert each element into the ST hash. Notes: Merged: https://github.com/ruby/ruby/pull/7846
2023-05-23Remove dead code in ar_copyPeter Zhu
new_tab can no longer ever be NULL so this is dead code.
2023-05-23Hash.new: print a deprecation warning when receiving keyword arguments (#7828)Jean byroot Boussier
[Feature #19236] In Ruby 3.3, `Hash.new` shall print a deprecation warning if keyword arguments are passed instead of treating them as an implicit positional Hash. This will allow to safely introduce a `capacity` keyword argument in 3.4 Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged-By: byroot <byroot@ruby-lang.org>
2023-05-17Move ar_hint to ar_table_structPeter Zhu
This allows Hashes with ST tables to fit int he 80 byte size pool. Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-17Implement Hash ST tables on VWAPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-17Implement Hash AR tables on VWAPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-12Add `rb_sys_fail_sprintf` macroNobuyoshi Nakada
2023-05-01[DOC] hash.c: fix typo in `#<=>` docsPiotr Szotkowski
Notes: Merged: https://github.com/ruby/ruby/pull/7771 Merged-By: nobu <nobu@ruby-lang.org>
2023-04-15Adjust function style [ci skip]Nobuyoshi Nakada
2023-04-11hash.c: Fix hash_iter_lev_dec corrupting shapeJean Boussier
[Bug #19589] When decrementing `iter_lev` from `65` to `64` the flags would be corrupted, causing the shape_id to be invalid. Notes: Merged: https://github.com/ruby/ruby/pull/7686
2023-04-06[Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec Notes: Merged: https://github.com/ruby/ruby/pull/7393
2023-03-24Change Hash#compact to keep default values and compare_by_identity flagJeremy Evans
The documentation states it returns a copy of self with nil value entries removed. However, the previous behavior was creating a plain new hash with non-nil values copied into it. This change aligns the behavior with the documentation. Fixes [Bug #19113] Notes: Merged: https://github.com/ruby/ruby/pull/6702
2023-03-24Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hashJeremy Evans
This was already copied for non-empty hashes. As Hash.ruby2_keywords_hash copies default values, it should also copy the compare_by_identity flag. Partially Fixes [Bug #19113] Notes: Merged: https://github.com/ruby/ruby/pull/6702
2023-03-24Do not copy compare_by_identity flag for non-empty hashes in Hash.[]Jeremy Evans
It wasn't copied for empty hashes, and Hash.[] doesn't copy the default value, so copying the compare_by_identity flag does not make sense. Partially Fixes [Bug #19113] Notes: Merged: https://github.com/ruby/ruby/pull/6702
2023-03-06Resurrect symbols used by ObjectSpaceTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-02-23Implement ObjectSpace::WeakKeyMap basic allocatorJean Boussier
[Feature #18498] Notes: Merged: https://github.com/ruby/ruby/pull/5570
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-09Merge gc.h and internal/gc.hMatt Valentine-House
[Feature #19425] Notes: Merged: https://github.com/ruby/ruby/pull/7273
2023-02-03Remove dead code in ar_copyPeter Zhu
All of the callers of ar_copy guarantee that hash2 has an ar table, so we don't need the logic to handle the case when hash2 doesn't have an ar table. Notes: Merged: https://github.com/ruby/ruby/pull/7230
2023-02-02Remove redundant else if statement in hash.cPeter Zhu
Hashes can only be ar or st, so the else if is redundant.
2023-01-31Remove rb_hash_ar_table_pPeter Zhu
It's dead code and duplicate of RHASH_AR_TABLE_P. Notes: Merged: https://github.com/ruby/ruby/pull/7211
2023-01-31Remove rb_hash_st_tablePeter Zhu
It's a duplicate of RHASH_ST_TABLE. Notes: Merged: https://github.com/ruby/ruby/pull/7211
2023-01-31Remove rb_hash_ar_tablePeter Zhu
It's dead code and duplicate of RHASH_AR_TABLE. Notes: Merged: https://github.com/ruby/ruby/pull/7211
2023-01-20Document thread-safety issues with Hash default_procJeremy Evans
Fixes [Bug #19237]
2023-01-11Assert possible hash functions in RHASH_ST_TABLE (#7107)Takashi Kokubun
Because of the function pointer, it's hard to figure out what hash functions could be used in Hash objects when st_lookup is used. Having this assertion makes it easier to understand what hash_stlike_lookup could possibly do. (AR uses only rb_any_hash) For example, this clarifies that hash_stlike_lookup never calls a #hash method when a key is T_STRING or T_SYMBOL. Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-12-17Use FL_TEST_RAW in rb_hash_default_valueJohn Hawthorn
We should always have a T_HASH here, so we can use FL_TEST_RAW to avoid checking whether we may have an immediate value. I expect this to be a very small performance improvement (perf stat ./miniruby benchmark/hash_aref_miss.rb shows a ~1% improvement). It also removes 9 instructions from rb_hash_default_value on x86_64. Notes: Merged: https://github.com/ruby/ruby/pull/6945
2022-12-17Use a BOP for Hash#defaultJohn Hawthorn
On a hash miss we need to call default if it is redefined in order to return the default value to be used. Previously we checked this with rb_method_basic_definition_p, which avoids the method call but requires a method lookup. This commit replaces the previous check with BASIC_OP_UNREDEFINED_P and a new BOP_DEFAULT. We still need to fall back to rb_method_basic_definition_p when called on a subclasss of hash. | |compare-ruby|built-ruby| |:---------------|-----------:|---------:| |hash_aref_miss | 2.692| 3.531| | | -| 1.31x| Co-authored-by: Daniel Colson <danieljamescolson@gmail.com> Co-authored-by: "Ian C. Anderson" <ian@iancanderson.com> Co-authored-by: Jack McCracken <me@jackmc.xyz> Notes: Merged: https://github.com/ruby/ruby/pull/6945
2022-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-10-24Adjust indents [ci skip]Nobuyoshi Nakada
2022-10-23Introduce `hash_iter_status_check` functionS.H
Notes: Merged: https://github.com/ruby/ruby/pull/6564 Merged-By: nobu <nobu@ruby-lang.org>
2022-10-22Improved formatting of `hash_foreach_iter` functions. (#6615)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-08-02[Bug #17767] Now `ENV.clone` raises `TypeError` as well as `ENV.dup`Nobuyoshi Nakada
One year ago, the former method has been deprecated while the latter has become an error. Then the 3.1 released, it is enough time to make also the former an error. Notes: Merged: https://github.com/ruby/ruby/pull/6155
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-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-06-17ENV.merge! support multile arguments [Feature #18279]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5207
2022-06-15Restore rb_exec_recursive_outerJohn Hawthorn
This was a public method, so we should probably keep it. Notes: Merged: https://github.com/ruby/ruby/pull/6027
2022-06-10Make method id explicit in rb_exec_recursive_outerJohn Hawthorn
Previously, because opt_aref and opt_aset don't push a frame, when they would call rb_hash to determine the hash value of the key, the initial level of recursion would incorrectly use the method id at the top of the stack instead of "hash". This commit replaces rb_exec_recursive_outer with rb_exec_recursive_outer_mid, which takes an explicit method id, so that we can make the hash calculation behave consistently. rb_exec_recursive_outer was documented as being internal, so I believe this should be okay to change. Notes: Merged: https://github.com/ruby/ruby/pull/6004
2022-04-30Document best-practices for writing hash methods (#5805)Chris Seaton
* Discussion is as per https://bugs.ruby-lang.org/issues/18611. Co-authored-by: Sam Bostock <sam.bostock@shopify.com> Notes: Merged-By: eregon <eregontp@gmail.com>
2022-04-26Expose `rb_hash_new_capa(long)`Jean Boussier
[Feature #18683] This allows parsers and similar libraries to create Hashes of a certain capacity in advance. It's useful when the key and values are streamed, hence `bulk_insert()` can't be used. Notes: Merged: https://github.com/ruby/ruby/pull/5835
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-02-12[DOC] Simplify operator method referencesNobuyoshi Nakada
2022-02-12Fix TypoSteven Nunez
Notes: Merged: https://github.com/ruby/ruby/pull/5548
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