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

709 Коммитов

Автор SHA1 Сообщение Дата
John Hawthorn 21994b7fd6 Avoid rehashing keys in transform_values
Previously, calling transform_values would call rb_hash_aset for each
key, needing to rehash it and look up its location.

Instead, we can use rb_hash_stlike_foreach_with_replace to replace the
values as we iterate without rehashing the keys.
2019-09-11 14:23:11 -07:00
Jeremy Evans 334b41a46b Allow ** syntax to be used for calling methods that do not accept keywords
Treat the ** syntax as passing a copy of the hash as the last
positional argument.  If the hash being double splatted is empty, do
not add a positional argument.

Remove rb_no_keyword_hash, no longer needed.
2019-08-30 12:39:31 -07:00
Yusuke Endoh 16c6984bb9 Separate keyword arguments from positional arguments
And, allow non-symbol keys as a keyword arugment
2019-08-30 12:39:31 -07:00
卜部昌平 3df37259d8 drop-in type check for rb_define_singleton_method
We can check the function pointer passed to
rb_define_singleton_method like how we do so in rb_define_method.
Doing so revealed many arity mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 50f5a0a8d6 rb_hash_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for rb_hash_foreach / st_foreach_safe.  Also fixes some prototype
mismatches.
2019-08-27 15:52:26 +09:00
Jeremy Evans e1c991f8d7 Move Object#hash rdoc to hash.c [ci skip]
This gets RDoc to pick up the documentation correctly.

Problem pointed out by zverok (Victor Shepelev).
2019-08-24 09:09:53 -07:00
Yusuke Endoh 3229e0583f hash.c: gc.h is needed when HASH_DEBUG mode 2019-08-07 22:54:38 +09:00
Yusuke Endoh 0cf6bfca78 hash.c: gc.h is no longer needed 2019-08-07 22:43:02 +09:00
Daniel Radetsky 82527d9b50
fix spelling
Closes: https://github.com/ruby/ruby/pull/2323
2019-08-07 22:25:50 +09:00
Koichi Sasada 3a6f51ee35 introduce ar_hint_t.
Hash hint for ar_array is 1 byte (unsigned char). This patch introduce
ar_hint_t which represents hint type.
2019-08-01 16:06:43 +09:00
Koichi Sasada 7463867106 use internal_id.
"hash_iter_lev" can be exported by Marshal.dump and it will
introduce inconsistency. To avoid this issue, use internal_id
instead of normal ID. This issue is pointed out by Chikanaga-san.
2019-08-01 11:22:43 +09:00
Koichi Sasada 117241b3c7 make inline functions from macros. 2019-08-01 05:59:04 +09:00
Koichi Sasada bd1052d55d use hash_ar_table_set() directly 2019-07-31 21:50:58 +01:00
Koichi Sasada deddc80476 HASH_ASSERT() respects HASH_DEBUG 2019-07-31 21:48:22 +01:00
Koichi Sasada 312879693f move macro to internal.h for documentation.
13e84d5c0a changes enum to macro, but the flags usage information
are lost in internal.h. It should be same place with other flags
information.
2019-07-31 11:32:14 +09:00
Nobuyoshi Nakada 13e84d5c0a
Moved RHASH_LEV_MASK and turned into a macro
Get rid of "ISO C restricts enumerator values to range of 'int'"
error.
2019-07-31 11:08:05 +09:00
git e315f3a134 * expand tabs. 2019-07-31 10:22:47 +09:00
Koichi Sasada 72825c35b0 Use 1 byte hint for ar_table [Feature #15602]
On ar_table, Do not keep a full-length hash value (FLHV, 8 bytes)
but keep a 1 byte hint from a FLHV (lowest byte of FLHV).
An ar_table only contains at least 8 entries, so hints consumes
8 bytes at most. We can store hints in RHash::ar_hint.

On 32bit CPU, we use 4 entries ar_table.

The advantages:
* We don't need to keep FLHV so ar_table only consumes
  16 bytes (VALUEs of key and value) * 8 entries = 128 bytes.
* We don't need to scan ar_table, but only need to check hints
  in many cases. Especially we don't need to access ar_table
  if there is no match entries (in many cases).
  It will increase memory cache locality.

The disadvantages:
* This technique can increase `#eql?` time because hints can
  conflicts (in theory, it conflicts once in 256 times).
  It can introduce incompatibility if there is a object x where
  x.eql? returns true even if hash values are different.
  I believe we don't need to care such irregular case.
* We need to re-calculate FLHV if we need to switch from ar_table
  to st_table (e.g. exceeds 8 entries).
  It also can introduce incompatibility, on mutating key objects.
  I believe we don't need to care such irregular case too.

Add new debug counters to measure the performance:
* artable_hint_hit - hint is matched and eql?#=>true
* artable_hint_miss - hint is not matched but eql?#=>false
* artable_hint_notfound - lookup counts
2019-07-31 09:52:03 +09:00
Koichi Sasada ebd398ac5a remove RHash::iter_lev.
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).
2019-07-31 09:44:23 +09:00
Nobuyoshi Nakada a036a8a038
Adjust styles and indents 2019-07-19 06:35:15 +09:00
Koichi Sasada c23e597674 respect RUBY_DEBUG.
see RUBY_DEBUG for each debug options.
2019-07-15 11:30:34 +09:00
Nobuyoshi Nakada bdddaa9f56
Use rb_ident_hash_new instead of rb_hash_new_compare_by_id
The latter is same as the former, removed the duplicate function.
2019-07-03 02:09:01 +09:00
Jeremy Evans f53d7e4bfd Raise TypeError if calling ENV.freeze
Previously, you could call ENV.freeze, but it would not have
the desired effect, as you could still modify ENV.

Fixes [Bug #15920]
2019-07-01 12:39:06 -07:00
Kenichi Kamiya d01fd82187 Alias ENV.merge! as ENV.update
[Feature #15947]

Closes: https://github.com/ruby/ruby/pull/2246
2019-06-21 18:25:01 +02:00
Yusuke Endoh d3f1c615c5 hash.c (rb_hash_s_create): Reject `Hash[[nil]]`
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]
2019-05-23 00:19:56 +09:00
Aaron Patterson 75061f46ae
Fix complex hash keys to work with compaction
For example when an array containing objects is a hash key, the contents
of the array may move which can cause the hash value for the array to
change.   This commit makes the default `hash` value based off the
object id, so the hash value will remain stable.

Fixes test/shell/test_command_processor.rb
2019-04-23 14:21:15 -07:00
k0kubun 683834eb72 Drop MJIT_FUNC_EXPORTED from rb_hash_bulk_insert
it's official API after r67677

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-21 08:34:37 +00:00
tenderlove 91793b8967 Add `GC.compact` again.
🙏

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 01:19:47 +00:00
tenderlove 744e5df715 Reverting compaction for now
For some reason symbols (or classes) are being overridden in trunk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 09:41:41 +00:00
ktsj 9738f96fcf Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 06:48:03 +00:00
tenderlove 3c55b643ae Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 03:17:25 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
tenderlove 3ef4db15e9 Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09 20:32:04 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
svn 8092d571be * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-27 03:26:09 +00:00
nobu 5e2a8cb7b9 Remove stale arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-27 03:26:05 +00:00
nobu e1e3d642bf hash.c: hoisted out st_index_hash
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 05:08:36 +00:00
nobu a94b78e418 hash.c: hoisted out dbl_to_index
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 04:54:01 +00:00
svn ef17936bc5 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 03:36:09 +00:00
nobu d07d192881 hash.c: remove repeated rb_hash_start
* hash.c (rb_dbl_long_hash): remove repeated rb_hash_start as
  rb_objid_hash includes rb_hash_start,

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 03:36:06 +00:00
ko1 367fdd1aee reset bound if the size is 0.
* hash.c (RHASH_AR_TABLE_SIZE_DEC): generally, we need to check all
  entries to calculate exact "bound" in ar_table, but if size == 0,
  we can clear bound because there are no active entries.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-17 07:52:47 +00:00
ko1 e3dbe84e12 add setter of iter_lev.
* hash.c: add special setter function (inc and dec).

* internal.h: constify RHash::iter_leve.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 19:11:32 +00:00
ko1 fc7f990666 fix last commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 22:41:59 +00:00
ko1 93583166c8 refactoring.
* hash.c (EQUAL, PTR_EQUAL): make corresponding inline functions
  ar_equal() and ar_ptr_equal().

* hash.c (SET_*): removed. set fields directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 22:40:32 +00:00
ko1 70caae18f2 add ar_ prefix for ar_table functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 22:23:54 +00:00
ko1 0c0d181e0f fix trivial indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 00:31:54 +00:00
ko1 2380111008 call functions directly.
* hash.c: ar_table only supports `objhash` so we can call compare/hash
  functions directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 00:06:09 +00:00
ko1 3a144485fc refactoring usage of ar_lookup().
* hash.c (hash_stlike_lookup): introduce inline a function and use it
  instead of using ar_lookup()/st_lookup() directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 23:48:33 +00:00
ko1 87e628d66b skip to calculate hash value on empty Hash ar_table lookup.
* hash.c (ar_lookup): don't calculate hash_value if ar_table is empty.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 07:49:00 +00:00
ko1 ba4672c2cb ar_table_entry::hash should be `st_hash_t`.
* hash.c: the type of `ar_table_entry::hash` is not a `VALUE`,
  but a `st_hash_t`.
  Also `st_hash_t` is not a `st_data_t`, but `st_index_t` (same as st.c).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 01:59:49 +00:00