aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
Commit message (Collapse)AuthorAgeFilesLines
* Enhancements for ENV docBurdetteLamar2019-12-221-13/+55
|
* Added rb_warn_deprecatedNobuyoshi Nakada2019-12-191-2/+2
|
* Enhancements for ENV docBurdetteLamar2019-12-161-46/+194
|
* Avoid unnecessary tzset() callKOSAKI Motohiro2019-12-011-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Akatsuki reported ENV['TZ'] = 'UTC' improved 7x-8x faster on following code. t = Time.now; 100000.times { Time.new(2019) }; Time.now - t https://hackerslab.aktsk.jp/2019/12/01/141551 commit 4bc1669127(reduce tzset) dramatically improved this situation. But still, TZ=UTC is faster than default. This patch removs unnecessary tzset() call completely. Performance check ---------------------- test program: t = Time.now; 100000.times { Time.new(2019) }; Time.now - t before: 0.387sec before(w/ TZ): 0.197sec after: 0.162sec after(w/ TZ): 0.165sec OK. Now, Time creation 2x faster *and* TZ=UTC doesn't improve anything. We can forget this hack completely. :) Side note: This patch slightly changes Time.new(t) behavior implicitly. Before this patch, it might changes default timezone implicitly. But after this patch, it doesn't. You need to reset TZ (I mean ENV['TZ'] = nil) explicitly. But I don't think this is big impact. Don't try to change /etc/localtime on runtime. Side note2: following test might be useful for testing "ENV['TZ'] = nil". ----------------------------------------- % cat <<'End' | sudo sh -s rm -f /etc/localtime-; cp -a /etc/localtime /etc/localtime- rm /etc/localtime; ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime ./ruby -e ' p Time.new(2000).zone # JST File.unlink("/etc/localtime"); File.symlink("/usr/share/zoneinfo/America/Los_Angeles", "/etc/localtime") p Time.new(2000).zone # JST (ruby does not follow /etc/localtime modification automatically) ENV["TZ"] = nil p Time.new(2000).zone # PST (ruby detect /etc/localtime modification) ' rm /etc/localtime; cp -a /etc/localtime- /etc/localtime; rm /etc/localtime- End
* ENV.update should not call block on existing keysNobuyoshi Nakada2019-11-301-3/+13
| | | | [Bug #16192]
* Improve consistency of bool/true/falseKazuhiro NISHIYAMA2019-11-251-1/+1
|
* make functions static卜部昌平2019-11-191-3/+5
| | | | | | | These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-46/+7
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-2/+0
| | | | | | | | | | | | | | | | | This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd.
* delete unused functions卜部昌平2019-11-141-2/+2
| | | | | | | | | | | | Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine.
* Use a monotonically increasing number for object_idJohn Hawthorn2019-11-071-2/+6
| | | | | | | | | | | | | | | | | This changes object_id from being based on the objects location in memory (or a nearby memory location in the case of a conflict) to be based on an always increasing number. This number is a Ruby Integer which allows it to overflow the size of a pointer without issue (very unlikely to happen in real programs especially on 64-bit, but a nice guarantee). This changes obj_to_id_tbl and id_to_obj_tbl to both be maps of Ruby objects to Ruby objects (previously they were Ruby object to C integer) which simplifies updating them after compaction as we can run them through gc_update_table_refs. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Revert "Use a monotonically increasing number for object_id"Aaron Patterson2019-11-061-6/+2
| | | | This reverts commit bd2b314a05ae9192b3143e1e678a37c370d8a9ce.
* Use a monotonically increasing number for object_idJohn Hawthorn2019-11-061-2/+6
| | | | | | | | | | | | | | | | | This changes object_id from being based on the objects location in memory (or a nearby memory location in the case of a conflict) to be based on an always increasing number. This number is a Ruby Integer which allows it to overflow the size of a pointer without issue (very unlikely to happen in real programs especially on 64-bit, but a nice guarantee). This changes obj_to_id_tbl and id_to_obj_tbl to both be maps of Ruby objects to Ruby objects (previously they were Ruby object to C integer) which simplifies updating them after compaction as we can run them through gc_update_table_refs. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Put an empty line [ci skip]Nobuyoshi Nakada2019-11-051-1/+2
|
* More rdoc for ENVBurdette Lamar2019-11-051-0/+28
|
* Correct documented return values for certain ENV methods (#2620)Burdette Lamar2019-11-021-8/+8
|
* hash.c: Do not use Unicode double-quotesYusuke Endoh2019-10-241-1/+1
| | | | | | | | | | | | | | | | It made rdoc fail. https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu1804/ruby-master/log/20191023T183005Z.fail.html.gz ``` RDoc is not a full Ruby parser and will fail when fed invalid ruby programs. The internal error was: (ArgumentError) invalid byte sequence in US-ASCII uh-oh! RDoc had a problem: invalid byte sequence in US-ASCII ```
* More rdoc for ENV#[] and ENV#fetchBurdetteLamar2019-10-231-13/+30
|
* [Bug #16121] adjusted indent [ci skip]Nobuyoshi Nakada2019-10-211-15/+15
|
* Stop making a redundant hash copy in Hash#dup (#2489)Dylan Thacker-Smith2019-10-211-55/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Stop making a redundant hash copy in Hash#dup It was making a copy of the hash without rehashing, then created an extra copy of the hash to do the rehashing. Since rehashing creates a new copy already, this change just uses that rehashing to make the copy. [Bug #16121] * Remove redundant Check_Type after to_hash * Fix freeing and clearing destination hash in Hash#initialize_copy The code was assuming the state of the destination hash based on the source hash for clearing any existing table on it. If these don't match, then that can cause the old table to be leaked. This can be seen by compiling hash.c with `#define HASH_DEBUG 1` and running the following script, which will crash from a debug assertion. ```ruby h = 9.times.map { |i| [i, i] }.to_h h.send(:initialize_copy, {}) ``` * Remove dead code paths in rb_hash_initialize_copy Given that `RHASH_ST_TABLE_P(h)` is defined as `(!RHASH_AR_TABLE_P(h))` it shouldn't be possible for a hash to be neither of these, so there is no need for the removed `else if` blocks. * Share implementation between Hash#replace and Hash#initialize_copy This also fixes key rehashing for small hashes backed by an array table for Hash#replace. This used to be done consistently in ruby 2.5.x, but stopped being done for small arrays in ruby 2.6.x. This also bring optimization improvements that were done for Hash#initialize_copy to Hash#replace. * Add the Hash#dup benchmark
* Use identhash as WeakMapNobuyoshi Nakada2019-10-181-1/+2
| | | | | As ObjectSpace::WeakMap allows FLONUM as a key, needs the special deal for its hash. [Feature #16035]
* Enhance doc for ENV.deleteBurdette Lamar2019-10-131-3/+15
|
* Fix more keyword separation issuesJeremy Evans2019-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | | This fixes instance_exec and similar methods. It also fixes Enumerator::Yielder#yield, rb_yield_block, and a couple of cases with Proc#{<<,>>}. This support requires the addition of rb_yield_values_kw, similar to rb_yield_values2, for passing the keyword flag. Unlike earlier attempts at this, this does not modify the rb_block_call_func type or add a separate function type. The functions of type rb_block_call_func are called by Ruby with a separate VM frame, and we can get the keyword flag information from the VM frame flags, so it doesn't need to be passed as a function argument. These changes require the following VM functions accept a keyword flag: * vm_yield_with_cref * vm_yield * vm_yield_with_block
* Fix documentation for ENV.each to return ENVJeremy Evans2019-09-201-2/+2
| | | | | | | | Also have spec check that it returns ENV. Mostly from burdettelamar@yahoo.com (Burdette Lamar). Fixes [Bug #16164]
* Avoid rehashing keys in transform_valuesJohn Hawthorn2019-09-111-7/+17
| | | | | | | | 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.
* Allow ** syntax to be used for calling methods that do not accept keywordsJeremy Evans2019-08-301-8/+0
| | | | | | | | 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.
* Separate keyword arguments from positional argumentsYusuke Endoh2019-08-301-0/+8
| | | | And, allow non-symbol keys as a keyword arugment
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-42/+69
| | | | | | 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.
* rb_hash_foreach now free from ANYARGS卜部昌平2019-08-271-14/+27
| | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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.
* Move Object#hash rdoc to hash.c [ci skip]Jeremy Evans2019-08-241-0/+19
| | | | | | This gets RDoc to pick up the documentation correctly. Problem pointed out by zverok (Victor Shepelev).
* 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