summaryrefslogtreecommitdiff
path: root/hash.c
AgeCommit message (Collapse)Author
2020-03-09Cast properly for shift operandKoichi Sasada
`(int) << RHASH_LEV_SHIFT` can be negative integer.
2020-03-07check ar_table first.Koichi Sasada
RHASH_AR_TABLE_SIZE() has assertion that it is a ar_talbe. The last commit breaks this assumption so check ar_table first.
2020-03-07check ar_table after `#hash` callKoichi Sasada
ar_table can be converted to st_table just after `ar_do_hash()` function which calls `#hash` method. We need to check the representation to detect this mutation. [Bug #16676]
2020-03-04fix compile error w/ -DUSE_TRANSIENT_HEAP=0卜部昌平
rb_transient_heap_managed_ptr_p is available only when USE_TRANSIENT_HEAP. Need #if guards.
2020-02-22hash.c: [DOC] fix examples for ENV.merge!Marcus Stollsteimer
2020-02-22More ENV rdoc [ci skip]Burdette Lamar
Notes: Merged: https://github.com/ruby/ruby/pull/2908 Merged-By: nobu <nobu@ruby-lang.org>
2020-02-20[DOC] Fixed `ENV.rassoc` result order [ci skip]Nobuyoshi Nakada
2020-02-19hash.c: [DOC] fix typosMarcus Stollsteimer
2020-02-15[DOC] use local variable like names [ci skip]Nobuyoshi Nakada
Use local variable like name as return value which is an instance of that class but not constant itself.
2020-02-14Fix typos and add a space [ci skip]Kazuhiro NISHIYAMA
2020-02-14Enhanced doc for ENVBurdette Lamar
* More on ENV examples Notes: Merged: https://github.com/ruby/ruby/pull/2905 Merged-By: nobu <nobu@ruby-lang.org>
2020-02-09Enhance rdoc for ENVBurdette Lamar
Notes: Merged: https://github.com/ruby/ruby/pull/2817 Merged-By: nobu <nobu@ruby-lang.org>
2020-01-28Extract a function, ruby_reset_timezone().Tanaka Akira
Initial implementation of ruby_reset_timezone() assigns ruby_tz_uptodate_p to false.
2020-01-23Added rb_warn_deprecated_to_removeNobuyoshi Nakada
Warn the deprecation and future removal, with obeying the warning flag.
2020-01-22Make taint warnings non-verbose instead of verboseJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2856
2020-01-17hash.c: Add a feature to manipulate ruby2_keywords flagYusuke Endoh
It was found that a feature to check and add ruby2_keywords flag to an existing Hash is needed when arguments are serialized and deserialized. It is possible to do the same without explicit APIs, but it would be good to provide them as a core feature. https://github.com/rails/rails/pull/38105#discussion_r361863767 Hash.ruby2_keywords_hash?(hash) checks if hash is flagged or not. Hash.ruby2_keywords_hash(hash) returns a duplicated hash that has a ruby2_keywords flag, [Bug #16486] Notes: Merged: https://github.com/ruby/ruby/pull/2818
2020-01-13reload AR table body for transient heap.Koichi Sasada
ar_talbe (Hash representation for <=8 size) can use transient heap and the memory area can move. So we need to restore `pair' ptr after `func` call (which can run any programs) because of moving.
2020-01-10Reduced duplicate codeNobuyoshi Nakada
2020-01-10Hash#transform_values should return a plain new HashNobuyoshi Nakada
[Bug #16498]
2020-01-08Hoisted out call_default_procNobuyoshi Nakada
2020-01-08Adjusted indents [ci skip]Nobuyoshi Nakada
2020-01-08Speeds up fallback to Hash#default_proc in rb_hash_aref by removing a method ↵Lourens Naudé
call Notes: Merged: https://github.com/ruby/ruby/pull/2821
2020-01-03move internal/debug.h definitions to internal.hKoichi Sasada
Debug utilities should be accessible from any internal code.
2019-12-26`#include "internal/debug"` seems to be needed in assert modeYusuke Endoh
http://ci.rvm.jp/results/trunk-theap-asserts@silicon-docker/2525210
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26internal/hash.h rework卜部昌平
Reduce macros to make them inline functions, as well as mark MJIT_FUNC_EXPORTED functions explicitly as such. Definition of ar_hint_t is simplified. This has been the only possible definition so far. Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26Transform hash keys by a hash [Feature #16274]Nobuyoshi Nakada
2019-12-22Enhancements for ENV docBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/2757
2019-12-19Added rb_warn_deprecatedNobuyoshi Nakada
2019-12-16Enhancements for ENV docBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/2751
2019-12-01Avoid unnecessary tzset() callKOSAKI Motohiro
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
2019-11-30ENV.update should not call block on existing keysNobuyoshi Nakada
[Bug #16192] Notes: Merged: https://github.com/ruby/ruby/pull/2512
2019-11-25Improve consistency of bool/true/falseKazuhiro NISHIYAMA
2019-11-19make functions static卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/2682
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-14delete unused functions卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/2677
2019-11-07Use a monotonically increasing number for object_idJohn Hawthorn
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>
2019-11-06Revert "Use a monotonically increasing number for object_id"Aaron Patterson
This reverts commit bd2b314a05ae9192b3143e1e678a37c370d8a9ce.
2019-11-06Use a monotonically increasing number for object_idJohn Hawthorn
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> Notes: Merged: https://github.com/ruby/ruby/pull/2638
2019-11-05Put an empty line [ci skip]Nobuyoshi Nakada
2019-11-05More rdoc for ENVBurdette Lamar
Notes: Merged: https://github.com/ruby/ruby/pull/2641
2019-11-02Correct documented return values for certain ENV methods (#2620)Burdette Lamar
2019-10-24hash.c: Do not use Unicode double-quotesYusuke Endoh
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 ```
2019-10-23More rdoc for ENV#[] and ENV#fetchBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/2579
2019-10-21[Bug #16121] adjusted indent [ci skip]Nobuyoshi Nakada
2019-10-21Stop making a redundant hash copy in Hash#dup (#2489)Dylan Thacker-Smith
* 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
2019-10-18Use identhash as WeakMapNobuyoshi Nakada
As ObjectSpace::WeakMap allows FLONUM as a key, needs the special deal for its hash. [Feature #16035]
2019-10-13Enhance doc for ENV.deleteBurdette Lamar
Notes: Merged: https://github.com/ruby/ruby/pull/2542
2019-09-26Fix more keyword separation issuesJeremy Evans
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 Notes: Merged: https://github.com/ruby/ruby/pull/2493