Граф коммитов

928 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans 5d6579bd91 Change Hash#compact to keep default values and compare_by_identity flag
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]
2023-03-24 10:55:13 -07:00
Jeremy Evans 1b13db25d8 Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hash
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]
2023-03-24 10:55:13 -07:00
Jeremy Evans d3197def88 Do not copy compare_by_identity flag for non-empty hashes in Hash.[]
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]
2023-03-24 10:55:13 -07:00
Takashi Kokubun 50a709fb9e Resurrect symbols used by ObjectSpace 2023-03-06 21:59:23 -08:00
Takashi Kokubun 233ddfac54 Stop exporting symbols for MJIT 2023-03-06 21:59:23 -08:00
Jean Boussier 2a5354e593 Implement ObjectSpace::WeakKeyMap basic allocator
[Feature #18498]
2023-02-23 16:01:57 +01:00
BurdetteLamar 3b239d2480 Remove (newly unneeded) remarks about aliases 2023-02-19 14:26:34 -08:00
Matt Valentine-House 72aba64fff Merge gc.h and internal/gc.h
[Feature #19425]
2023-02-09 10:32:29 -05:00
Peter Zhu e30cf60a19 Remove dead code in ar_copy
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.
2023-02-03 14:59:00 -05:00
Peter Zhu 5b34839b0f Remove redundant else if statement in hash.c
Hashes can only be ar or st, so the else if is redundant.
2023-02-02 14:43:50 -05:00
Peter Zhu 9f9dca0c52 Remove rb_hash_ar_table_p
It's dead code and duplicate of RHASH_AR_TABLE_P.
2023-01-31 15:48:09 -05:00
Peter Zhu 2296b877d8 Remove rb_hash_st_table
It's a duplicate of RHASH_ST_TABLE.
2023-01-31 15:48:09 -05:00
Peter Zhu 2866f951c5 Remove rb_hash_ar_table
It's dead code and duplicate of RHASH_AR_TABLE.
2023-01-31 15:48:09 -05:00
Jeremy Evans ffd52412ab Document thread-safety issues with Hash default_proc
Fixes [Bug #19237]
2023-01-20 08:36:06 -08:00
Takashi Kokubun d4a3882c1c
Assert possible hash functions in RHASH_ST_TABLE (#7107)
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.
2023-01-11 23:14:58 -08:00
John Hawthorn ea3d3c4552 Use FL_TEST_RAW in rb_hash_default_value
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.
2022-12-17 14:51:49 -08:00
John Hawthorn fbaa5db44a Use a BOP for Hash#default
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>
2022-12-17 14:51:49 -08:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Nobuyoshi Nakada c3e37f74ae
Adjust indents [ci skip] 2022-10-24 00:22:37 +09:00
S.H c8c136265c
Introduce `hash_iter_status_check` function 2022-10-23 16:17:24 +09:00
Samuel Williams 8dfe3bdf48
Improved formatting of `hash_foreach_iter` functions. (#6615) 2022-10-22 23:34:00 +13:00
Nobuyoshi Nakada ec3f59309e [Bug #17767] Now `ENV.clone` raises `TypeError` as well as `ENV.dup`
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.
2022-08-02 16:40:12 +09:00
Peter Zhu efb91ff19b Rename rb_ary_tmp_new to rb_ary_hidden_new
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.
2022-07-26 09:12:09 -04:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada 278fefb962 ENV.merge! support multile arguments [Feature #18279] 2022-06-17 01:22:24 +09:00
John Hawthorn 17d260a87f Restore rb_exec_recursive_outer
This was a public method, so we should probably keep it.
2022-06-15 16:07:29 -07:00
John Hawthorn 52da90acee Make method id explicit in rb_exec_recursive_outer
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.
2022-06-10 14:48:21 -07:00
Chris Seaton 3a8d60f503
Document best-practices for writing hash methods (#5805)
* Discussion is as per https://bugs.ruby-lang.org/issues/18611.

Co-authored-by: Sam Bostock <sam.bostock@shopify.com>
2022-04-30 12:57:51 +02:00
Jean Boussier 4a2b5102c1 Expose `rb_hash_new_capa(long)`
[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.
2022-04-26 16:12:47 +02:00
Nobuyoshi Nakada 300f4677c9
[DOC] Use simple references to operator methods
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-26 21:13:16 +09:00
Burdette Lamar 1a002d9ade
Fix formatting errors in What's Here for Array, Hash, ENV (#5718) 2022-03-25 13:48:21 -05:00
Nobuyoshi Nakada 50c972a1ae
[DOC] Simplify operator method references 2022-02-12 12:38:36 +09:00
Steven Nunez 68be9a9ae8 Fix Typo 2022-02-12 10:43:27 +09:00
Nobuyoshi Nakada 16fdc1ff46
[DOC] Fix broken links to literals.rdoc 2022-02-08 01:27:52 +09:00
Nobuyoshi Nakada bc5662d9d8
[DOC] Simplify links to global methods 2022-02-08 01:18:56 +09:00
Peter Zhu a32e5e1b97 [DOC] Use RDoc link style for links in the same class/module
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
2022-02-07 09:52:06 -05:00
Peter Zhu f9a2802bc5 [DOC] Use RDoc link style for links to other classes/modules
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
2022-02-07 09:52:06 -05:00
Aaron Patterson 2a76440fac [Bug #18501] Fire write barrier after hash has been written
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
2022-02-04 14:36:04 -08:00
Jeremy Evans a93cc3e23b Make Hash#shift return nil for empty hash
Fixes [Bug #16908]
2022-01-14 12:17:57 -08:00
Nobuyoshi Nakada 39bc5de833
Remove tainted and trusted features
Already these had been announced to be removed in 3.2.
2021-12-26 23:28:54 +09:00
Kazuhiro NISHIYAMA 48a0905d25
Add missing '%' in format string 2021-12-21 18:21:03 +09:00
Victor Shepelev a0f10a973f
[DOC] Add documentation for hash value omission syntax 2021-12-20 01:09:52 +09:00
Burdette Lamar 7e0e6f9074
What's Here for ENV (#5292)
[DOC] What's Here for ENV
2021-12-18 12:32:11 -06:00
Koichi Sasada ce6fc20f97 data type should be `static` 2021-12-17 15:46:50 +09:00
Koichi Sasada c8f2766ae2 `RUBY_DEFAULT_FREE` is not needed.
pointed by @nobu.
2021-12-17 15:46:50 +09:00
Koichi Sasada 37bd795cf8 `ENV` ivars should not be accessible from ractors
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
2021-12-17 15:46:50 +09:00
Nobuyoshi Nakada 05c9dfe23a
Suppress empty-body warning 2021-12-16 14:19:28 +09:00
Nobuyoshi Nakada 0f99f3fe5e
Adjust indents [ci skip] 2021-12-15 15:31:46 +09:00
Koichi Sasada 0eafba3610 use `RB_VM_LOCK_ENTER()`
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`.
2021-12-15 15:04:34 +09:00
Nobuyoshi Nakada a4a3528eb7 Removed no longer used variables 2021-12-15 15:04:34 +09:00