summaryrefslogtreecommitdiff
path: root/hash.c
AgeCommit message (Collapse)Author
2021-10-02Restore Hash#compare_by_identity mode [Bug #18171]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4893
2021-10-02Add rb_ident_hash_new_with_sizeNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4893
2021-09-30Use faster any_hash logic in rb_hashJohn Hawthorn
From the documentation of rb_obj_hash: > Certain core classes such as Integer use built-in hash calculations and > do not call the #hash method when used as a hash key. So if you override, say, Integer#hash it won't be used from rb_hash_aref and similar. This avoids method lookups in many common cases. This commit uses the same optimization in rb_hash, a method used internally and in the C API to get the hash value of an object. Usually this is used to build the hash of an object based on its elements. Previously it would always do a method lookup for 'hash'. This is primarily intended to speed up hashing of Arrays and Hashes, which call rb_hash for each element. compare-ruby: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux] built-ruby: ruby 3.1.0dev (2021-09-29T02:13:24Z fast_hash d670bf88b2) [x86_64-linux] # Iteration per second (i/s) | |compare-ruby|built-ruby| |:----------------|-----------:|---------:| |hash_aref_array | 1.008| 1.769| | | -| 1.76x| Notes: Merged: https://github.com/ruby/ruby/pull/4916
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-14Handle overwriting Object::ENV in spawnJeremy Evans
Instead of looking for Object::ENV (which can be overwritten), directly look for the envtbl variable. As that is static in hash.c, and the lookup code is in process.c, add a couple non-static functions that will return envtbl (or envtbl#to_hash). Fixes [Bug #18164] Notes: Merged: https://github.com/ruby/ruby/pull/4834
2021-09-14Revert "Force recycle intermediate collection in Hash#transform_keys! [Bug ↵Kenichi Kamiya
#17735]" This reverts commit 522d4cd32f7727886f4fcbc28ed29c08d361ee20. Notes: Merged: https://github.com/ruby/ruby/pull/4341
2021-09-11Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4805
2021-08-29Free previously used tables [Bug #18134]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4788
2021-08-26Make Hash#each family usable in RactorSutou Kouhei
We don't need to increment/decrement iteration level for frozen Hash because frozen Hash can't be modified. We can assume that nobody changes the target Hash while calling #each family. How to reproduce: a = {} 100.times do |i| a[i] = true end Ractor.make_shareable(a) 4.times.collect do Ractor.new(a) do |b| 100.times do b.each_value do end end end end.each(&:take) Example output: internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. #<Thread:0x00007fcfb087bb30 run> terminated with exception (report_on_exception is true): #<Thread:0x00007fcfb087b8d8 run> terminated with exception (report_on_exception is true): #<Thread:0x00007fcfb088d678 run> terminated with exception (report_on_exception is true): #<Thread:0x00007fcfb087bd88 run> terminated with exception (report_on_exception is true): /tmp/h.rb:10:in `each_value'/tmp/h.rb:10:in `each_value': : /tmp/h.rb:10:in `each_value'no implicit conversion from nil to integer/tmp/h.rb:10:in `each_value'no implicit conversion from nil to integer (: : (TypeErrorTypeError)no implicit conversion from nil to integer)no implicit conversion from nil to integer ( (TypeErrorTypeError from /tmp/h.rb:10:in `block (3 levels) in <main>' from /tmp/h.rb:10:in `block (3 levels) in <main>' )) from /tmp/h.rb:9:in `times' from /tmp/h.rb:9:in `times' from /tmp/h.rb:9:in `block (2 levels) in <main>' from /tmp/h.rb:10:in `block (3 levels) in <main>' from /tmp/h.rb:10:in `block (3 levels) in <main>' from /tmp/h.rb:9:in `block (2 levels) in <main>' from /tmp/h.rb:9:in `times' from /tmp/h.rb:9:in `times' from /tmp/h.rb:9:in `block (2 levels) in <main>' from /tmp/h.rb:9:in `block (2 levels) in <main>' <internal:ractor>:694:in `take': thrown by remote Ractor. (Ractor::RemoteError) from /tmp/h.rb:14:in `each' from /tmp/h.rb:14:in `<main>' /tmp/h.rb:10:in `each_value': no implicit conversion from nil to integer (TypeError) from /tmp/h.rb:10:in `block (3 levels) in <main>' from /tmp/h.rb:9:in `times' from /tmp/h.rb:9:in `block (2 levels) in <main>' Notes: Merged: https://github.com/ruby/ruby/pull/4768
2021-08-19Remove old warning aged nearly 8 yearsNobuyoshi Nakada
2021-08-07Stop force-recycling evacuated array [Bug #18065]Nobuyoshi Nakada
2021-08-02Using RBOOL macroS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4695 Merged-By: nobu <nobu@ruby-lang.org>
2021-07-28Fix a comment [ci skip]Nobuyoshi Nakada
2021-07-22Remove useless castsNobuyoshi Nakada
2021-07-15Copy hash compare_by_identity setting in more casesJeremy Evans
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> Notes: Merged: https://github.com/ruby/ruby/pull/4616 Merged-By: jeremyevans <code@jeremyevans.net>
2021-07-04[DOC] `Hash.[]` returns a hash with no default value/proc [ci skip]Nobuyoshi Nakada
2021-06-30Specify version to remove as bare numbersNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3972
2021-06-30rb_warn_deprecated_to_remove_at [Feature #17432]Nobuyoshi Nakada
At compilation time with RUBY_DEBUG enabled, check if the removal version has been reached. Notes: Merged: https://github.com/ruby/ruby/pull/3972
2021-06-28Share freeze option handlingNobuyoshi Nakada
2021-06-24[DOC] fixed return value of ENV.clone [ci skip]Nobuyoshi Nakada
2021-06-21What's Here for Numeric and ComparableBurdette Lamar
2021-06-17Adjust styles [ci skip]Nobuyoshi Nakada
* --braces-after-func-def-line * --dont-cuddle-else * --procnames-start-lines * --space-after-for * --space-after-if * --space-after-while
2021-06-08Make ENV.clone warn and ENV.dup raiseJeremy Evans
ENV.dup returned a plain Object, since all of ENV's behavior is defined in ENV's singleton class. So using dup makes no sense. ENV.clone works and is used in some gems, but it doesn't do what the user expects, since modifying ENV.clone also modifies ENV. Add a deprecation warning pointing the user to use ENV.to_h instead. This also undefines some private initialize* methods in ENV, since they are not needed. Fixes [Bug #17767] Notes: Merged: https://github.com/ruby/ruby/pull/4557 Merged-By: jeremyevans <code@jeremyevans.net>
2021-06-01Add static modifier to C function in hash.c (#3138)S.H
* add static modifier for rb_hash_reject_bang func * add static modifier for rb_hash_reject func * add static modifier for rb_hash_values_at func * add static modifier for rb_hash_assoc func * add static modifier for rb_hash_rassoc func Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2021-05-07Protoized old pre-ANSI K&R style declarations and definitionsNobuyoshi Nakada
2021-05-04Fix trivial -Wundef warningsBenoit Daloze
* See [Feature #17752] Co-authored-by: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/4428
2021-04-30Correct documentation example on Hash#digNick Kelley
Fixes [Misc #17842]. The current documentation suggests that: {foo: {bar: {baz: 2}}}.dig(:foo, :bar) # => {:bar=>{:baz=>2}} when it should be: {foo: {bar: {baz: 2}}}.dig(:foo, :bar) # => {:baz=>2} Notes: Merged: https://github.com/ruby/ruby/pull/4441
2021-04-23Fix wrong documentationromainsalles
It doesn't return `nil` but raises an exception, as explained a few lines after Notes: Merged: https://github.com/ruby/ruby/pull/4403
2021-04-15[Doc] Add Hash#value? into call-seq (#4293)Kenichi Kamiya
Notes: Merged-By: zzak
2021-03-28Force recycle intermediate collection in Hash#transform_keys! [Bug #17735]Kenichi Kamiya
* Force recycle intermediate hash * Force recycle intermediate array too https://github.com/ruby/ruby/pull/4329#issuecomment-808840718 Notes: Merged-By: nobu <nobu@ruby-lang.org>
2021-03-28Hide an intermediate arrayNobuyoshi Nakada
2021-03-28Clear an intermediate hash [Bug #17735]Nobuyoshi Nakada
2021-03-28Keep non evaluated keys in `Hash#transform_keys!` [Bug #17735]Kenichi Kamiya
Notes: Merged: https://github.com/ruby/ruby/pull/4294 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-22[Doc] Fix a typo around Hash#compare_by_identityKenichi Kamiya
Notes: Merged: https://github.com/ruby/ruby/pull/4303
2021-03-22Hash#transform_values! ensures receiver modifiable in block [Bug #17736]Kenichi Kamiya
Notes: Merged: https://github.com/ruby/ruby/pull/4302 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-21Ensure the receiver hash modifiable before updating [Bug #17736]Nobuyoshi Nakada
Close https://github.com/ruby/ruby/pull/4298 Notes: Merged: https://github.com/ruby/ruby/pull/4299
2021-03-21Refactor hash aset callbackNobuyoshi Nakada
2021-03-20Refactor hash update callbacksNobuyoshi Nakada
2021-03-20Some Hash destructive methods ensure the receiver modifiable [Bug #17736]Kenichi Kamiya
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 Notes: Merged: https://github.com/ruby/ruby/pull/4297
2021-03-18Avoid rehashing in Hash#replace/dup/initialize_copy [Bug #16996]Marc-Andre Lafortune
2021-03-18Avoid rehashing in Hash#select/reject [Bug #16996]Marc-Andre Lafortune
2021-01-20Explicit references to EnumerableBurdetteLamar
2021-01-10Adds RDoc summary of Hash methods (#4045)Burdette Lamar
* Adds RDoc summary of Hash methods Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-12-31Make any hash values fixable [Bug #17488]Nobuyoshi Nakada
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>
2020-12-28Adjusted indents [ci skip]Nobuyoshi Nakada
2020-12-25Optimize calls to `Kernel#hash` (#3987)Marc-André Lafortune
This avoids recursive checks when the `hash` method of an object isn't specialized. Notes: Merged-By: nurse <naruse@airemix.jp>
2020-12-19Make `Hash#except` always return a HashMarc-Andre Lafortune
[Feature #15822] Notes: Merged: https://github.com/ruby/ruby/pull/3929
2020-12-15Document Hash#transform_keys with hash. Amend NEWS [DOC] [ci skip]Marc-Andre Lafortune
2020-12-08Windows: Read ENV names and values as UTF-8 encoded Strings (#3818)Lars Kanis
* Windows: Read ENV names and values as UTF-8 encoded Strings Implements issue #12650: fix https://bugs.ruby-lang.org/issues/12650 This also removes the special encoding for ENV['PATH'] and some complexity in the code that is unnecessary now. * Windows: Improve readablity of getenv() encoding getenv() did use the expected codepage as an implicit parameter of the macro. This is mis-leading since include/ruby/win32.h has a different definition. Using the "cp" variable explicit (like the other function calls) makes it more readable and consistent. * Windows: Change external C-API macros getenv() and execv() to use UTF-8 They used to process and return strings with locale encoding, but since all ruby-internal spawn and environment functions use UTF-8, it makes sense to change the C-API equally. Notes: Merged-By: nurse <naruse@airemix.jp>
2020-12-07Hash#index: delete卜部昌平
Has been deprecated since 0c97c8e33584e6203bb09c08f92b63bd2cca8ae7.