summaryrefslogtreecommitdiff
path: root/hash.c
Commit message (Collapse)AuthorAgeFilesLines
* [Bug #17767] Now `ENV.clone` raises `TypeError` as well as `ENV.dup`Nobuyoshi Nakada2022-08-021-13/+8
| | | | | | 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.
* Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu2022-07-261-1/+1
| | | | | | 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.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-273/+273
| | | | [Misc #18891]
* ENV.merge! support multile arguments [Feature #18279]Nobuyoshi Nakada2022-06-171-10/+15
|
* Restore rb_exec_recursive_outerJohn Hawthorn2022-06-151-0/+1
| | | | This was a public method, so we should probably keep it.
* Make method id explicit in rb_exec_recursive_outerJohn Hawthorn2022-06-101-1/+1
| | | | | | | | | | | | | | 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.
* Document best-practices for writing hash methods (#5805)Chris Seaton2022-04-301-0/+13
| | | | | * Discussion is as per https://bugs.ruby-lang.org/issues/18611. Co-authored-by: Sam Bostock <sam.bostock@shopify.com>
* Expose `rb_hash_new_capa(long)`Jean Boussier2022-04-261-0/+6
| | | | | | | | [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.
* [DOC] Use simple references to operator methodsNobuyoshi Nakada2022-03-261-4/+4
| | | | | | | 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.
* Fix formatting errors in What's Here for Array, Hash, ENV (#5718)Burdette Lamar2022-03-251-113/+113
|
* [DOC] Simplify operator method referencesNobuyoshi Nakada2022-02-121-5/+5
|
* Fix TypoSteven Nunez2022-02-121-1/+1
|
* [DOC] Fix broken links to literals.rdocNobuyoshi Nakada2022-02-081-1/+1
|
* [DOC] Simplify links to global methodsNobuyoshi Nakada2022-02-081-1/+1
|
* [DOC] Use RDoc link style for links in the same class/modulePeter Zhu2022-02-071-49/+49
| | | | | | | | | | 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
* [DOC] Use RDoc link style for links to other classes/modulesPeter Zhu2022-02-071-4/+4
| | | | | | | | | | 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
* [Bug #18501] Fire write barrier after hash has been writtenAaron Patterson2022-02-041-5/+15
| | | | | | | | | | | | | | | | | Before this change the write barrier was executed before the key and value were actually reachable via the Hash. This could cause inconsistencies in object coloration which would lead to accidental collection of dup'd keys. Example: 1. Object O is grey, Object P is white. 2. Write barrier fires O -> P 3. Write barrier does nothing 4. Malloc happens, which starts GC 5. GC colors O black 6. P is written in to O (now we have O -> P reference) 7. P is now accidentally treated as garbage
* Make Hash#shift return nil for empty hashJeremy Evans2022-01-141-4/+3
| | | | Fixes [Bug #16908]
* Remove tainted and trusted featuresNobuyoshi Nakada2021-12-261-7/+0
| | | | Already these had been announced to be removed in 3.2.
* Add missing '%' in format stringKazuhiro NISHIYAMA2021-12-211-1/+1
|
* [DOC] Add documentation for hash value omission syntaxVictor Shepelev2021-12-201-0/+8
|
* What's Here for ENV (#5292)Burdette Lamar2021-12-181-0/+80
| | | [DOC] What's Here for ENV
* data type should be `static`Koichi Sasada2021-12-171-1/+1
|
* `RUBY_DEFAULT_FREE` is not needed.Koichi Sasada2021-12-171-1/+1
| | | | pointed by @nobu.
* `ENV` ivars should not be accessible from ractorsKoichi Sasada2021-12-171-1/+12
| | | | | | | The `ENV` object can have instance variables like other objects, but they should be accessed only on the main ractor. fix https://github.com/ruby/ruby/pull/5263#issuecomment-995585766
* Suppress empty-body warningNobuyoshi Nakada2021-12-161-2/+2
|
* Adjust indents [ci skip]Nobuyoshi Nakada2021-12-151-3/+3
|
* use `RB_VM_LOCK_ENTER()`Koichi Sasada2021-12-151-337/+375
| | | | | | We found that we need to make Ruby objects while locking the environ to ENV operation atomically, so we decided to use `RB_VM_LOCK_ENTER()` instead of `env_lock`.
* Removed no longer used variablesNobuyoshi Nakada2021-12-151-7/+0
|
* Fixed env_pairs array typesNobuyoshi Nakada2021-12-151-8/+8
|
* Use prototype definition instead of old K&R styleNobuyoshi Nakada2021-12-151-1/+1
|
* Adjust styles [ci skip]Nobuyoshi Nakada2021-12-151-17/+10
| | | | | * --braces-after-func-def-line * --space-after-for
* Symbols closed to env should be staticNobuyoshi Nakada2021-12-151-2/+2
|
* Make ENV shareableRohit Menon2021-12-151-0/+3
|
* Move exception-raising functions out of mutex; Refactor env-copyingRohit Menon2021-12-151-98/+61
|
* Add locks for ENVRohit Menon2021-12-151-46/+183
|
* Adding links to literals and Kernel (#5192)Burdette Lamar2021-12-031-9/+5
| | | | * Adding links to literals and Kernel
* [Feature #18290] Remove all usages of rb_gc_force_recyclePeter Zhu2021-11-081-2/+0
| | | | | This commit removes usages of rb_gc_force_recycle since it is a burden to maintain and makes changes to the GC difficult.
* Restore Hash#compare_by_identity mode [Bug #18171]Nobuyoshi Nakada2021-10-021-3/+1
|
* Add rb_ident_hash_new_with_sizeNobuyoshi Nakada2021-10-021-0/+8
|
* Use faster any_hash logic in rb_hashJohn Hawthorn2021-09-301-29/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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|
* [DOC] Fix broken links [ci skip]Nobuyoshi Nakada2021-09-151-1/+1
| | | | | | * 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.
* Handle overwriting Object::ENV in spawnJeremy Evans2021-09-141-0/+12
| | | | | | | | | 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]
* Revert "Force recycle intermediate collection in Hash#transform_keys! [Bug ↵Kenichi Kamiya2021-09-141-1/+0
| | | | | | #17735]" This reverts commit 522d4cd32f7727886f4fcbc28ed29c08d361ee20.
* Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS2021-09-111-1/+1
|
* Free previously used tables [Bug #18134]Nobuyoshi Nakada2021-08-291-15/+7
|
* Make Hash#each family usable in RactorSutou Kouhei2021-08-261-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>'
* Remove old warning aged nearly 8 yearsNobuyoshi Nakada2021-08-191-23/+0
|
* Stop force-recycling evacuated array [Bug #18065]Nobuyoshi Nakada2021-08-071-1/+0
|
* Using RBOOL macroS.H2021-08-021-16/+5
|