summaryrefslogtreecommitdiff
path: root/hash.c
Commit message (Collapse)AuthorAgeFilesLines
* hash.c: gc.h is needed when HASH_DEBUG modeYusuke Endoh2019-08-071-0/+4
|
* hash.c: gc.h is no longer neededYusuke Endoh2019-08-071-1/+0
|
* fix spellingDaniel Radetsky2019-08-071-2/+2
| | | | Closes: https://github.com/ruby/ruby/pull/2323
* introduce ar_hint_t.Koichi Sasada2019-08-011-9/+10
| | | | | Hash hint for ar_array is 1 byte (unsigned char). This patch introduce ar_hint_t which represents hint type.
* use internal_id.Koichi Sasada2019-08-011-2/+4
| | | | | | "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.
* make inline functions from macros.Koichi Sasada2019-08-011-25/+36
|
* use hash_ar_table_set() directlyKoichi Sasada2019-07-311-7/+5
|
* HASH_ASSERT() respects HASH_DEBUGKoichi Sasada2019-07-311-1/+1
|
* move macro to internal.h for documentation.Koichi Sasada2019-07-311-1/+0
| | | | | | 13e84d5c0a changes enum to macro, but the flags usage information are lost in internal.h. It should be same place with other flags information.
* Moved RHASH_LEV_MASK and turned into a macroNobuyoshi Nakada2019-07-311-1/+2
| | | | | Get rid of "ISO C restricts enumerator values to range of 'int'" error.
* * expand tabs.git2019-07-311-4/+4
|
* Use 1 byte hint for ar_table [Feature #15602]Koichi Sasada2019-07-311-146/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* remove RHash::iter_lev.Koichi Sasada2019-07-311-2/+58
| | | | | | | | | | | | | | | 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).
* Adjust styles and indentsNobuyoshi Nakada2019-07-191-1/+2
|
* respect RUBY_DEBUG.Koichi Sasada2019-07-151-2/+2
| | | | see RUBY_DEBUG for each debug options.
* Use rb_ident_hash_new instead of rb_hash_new_compare_by_idNobuyoshi Nakada2019-07-031-8/+0
| | | | The latter is same as the former, removed the duplicate function.
* Raise TypeError if calling ENV.freezeJeremy Evans2019-07-011-0/+15
| | | | | | | Previously, you could call ENV.freeze, but it would not have the desired effect, as you could still modify ENV. Fixes [Bug #15920]
* Alias ENV.merge! as ENV.updateKenichi Kamiya2019-06-211-0/+3
| | | | | | [Feature #15947] Closes: https://github.com/ruby/ruby/pull/2246
* hash.c (rb_hash_s_create): Reject `Hash[[nil]]`Yusuke Endoh2019-05-231-9/+0
| | | | | | | 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]
* Fix complex hash keys to work with compactionAaron Patterson2019-04-231-1/+5
| | | | | | | | | 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
* Drop MJIT_FUNC_EXPORTED from rb_hash_bulk_insertk0kubun2019-04-211-1/+1
| | | | | | it's official API after r67677 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add `GC.compact` again.tenderlove2019-04-201-1/+39
| | | | | | 🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Reverting compaction for nowtenderlove2019-04-171-39/+1
| | | | | | 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
* Introduce pattern matching [EXPERIMENTAL]ktsj2019-04-171-0/+8
| | | | | | [ruby-core:87945] [Feature #14912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adding `GC.compact` and compacting GC support.tenderlove2019-04-171-1/+39
| | | | | | | | | | | 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
* Reverting all commits from r67479 to r67496 because of CI failureskazu2019-04-101-39/+1
| | | | | | | | 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
* Adding `GC.compact` and compacting GC support.tenderlove2019-04-091-1/+39
| | | | | | | | | | | 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
* [DOC] fix markups [ci skip]nobu2019-03-221-19/+18
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-02-271-6/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Remove stale argumentsnobu2019-02-271-13/+21
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: hoisted out st_index_hashnobu2019-01-301-3/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: hoisted out dbl_to_indexnobu2019-01-301-9/+10
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-01-301-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: remove repeated rb_hash_startnobu2019-01-301-1/+1
| | | | | | | * 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
* reset bound if the size is 0.ko12019-01-171-5/+15
| | | | | | | | | * 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
* add setter of iter_lev.ko12019-01-091-3/+15
| | | | | | | | | * 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
* fix last commit.ko12019-01-051-5/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* refactoring.ko12019-01-051-14/+22
| | | | | | | | | | * 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
* add ar_ prefix for ar_table functions.ko12019-01-051-36/+33
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix trivial indentation.ko12019-01-051-3/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* call functions directly.ko12019-01-051-2/+2
| | | | | | | | * 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
* refactoring usage of ar_lookup().ko12019-01-041-45/+44
| | | | | | | | * 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
* skip to calculate hash value on empty Hash ar_table lookup.ko12019-01-041-8/+13
| | | | | | | * 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
* ar_table_entry::hash should be `st_hash_t`.ko12019-01-041-30/+30
| | | | | | | | | * 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
* hide ar_table internals from internal.h.ko12018-12-291-0/+29
| | | | | | | | | | | * internal.h: move ar_table def to hash.c because other files don't need to know implementation of ar_table. * hash.c (rb_hash_ar_table_size): added because gc.c needs to know the size_of(ar_table). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hide iseq operand object for duphash. [Bug #15440]ko12018-12-201-0/+7
| | | | | | | | | | * compile.c (compile_array): hide source Hash object. * hash.c (rb_hash_resurrect): introduced to dup Hash object using rb_cHash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* separte NULL and EMPTY check.ko12018-12-141-31/+41
| | | | | | | | | | | | * hash.c: separate NULL and EMPTY check functions. `RHASH_TABLE_EMPTY` function checks NULL table or not, but it should be named "NULL_P". Introduce `RHASH_TABLE_EMPTY_P` function to check size == 0. There are cases that hash has table data even if data is not NULL (in case removed after inserted elements). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rename li_table->ar_table (and related names).ko12018-12-141-278/+279
| | | | | | | | | | | | | | | | | | | * internal.h: rename the following names: * li_table -> ar_table. "li" means linear (from linear search), but we use the word "array" (from data layout). * RHASH_ARRAY -> RHASH_AR_TABLE. AR_TABLE is more clear. * rb_hash_array_* -> rb_hash_ar_table_*. * RHASH_TABLE_P() -> RHASH_ST_TABLE_P(). more clear. * RHASH_CLEAR() -> RHASH_ST_CLEAR(). * hash.c: rename "linear_" prefix functions to "ar_" prefix. * hash.c (linear_init_table): rename to ar_alloc_table. * debug_counter.h: rename obj_hash_array to obj_hash_ar. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Initialize binnobu2018-12-101-1/+1
| | | | | | | * hash.c (linear_update): initialize `bin` just to silence false warnings by old gcc 4.8. [Bug #15299] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adjust reserved hash valuesnobu2018-12-071-2/+7
| | | | | | | The reserved hash values in hash.c must be consistend with st.c. [ruby-core:90356] [Bug #15389] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e