summaryrefslogtreecommitdiff
path: root/hash.c
AgeCommit message (Collapse)Author
2019-01-09add setter of iter_lev.ko1
* 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-05fix last commit.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05refactoring.ko1
* 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-05add ar_ prefix for ar_table functions.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05fix trivial indentation.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05call functions directly.ko1
* 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-04refactoring usage of ar_lookup().ko1
* 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-04skip to calculate hash value on empty Hash ar_table lookup.ko1
* 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-04ar_table_entry::hash should be `st_hash_t`.ko1
* 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
2018-12-29hide ar_table internals from internal.h.ko1
* 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
2018-12-20hide iseq operand object for duphash. [Bug #15440]ko1
* 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
2018-12-14separte NULL and EMPTY check.ko1
* 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
2018-12-14rename li_table->ar_table (and related names).ko1
* 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
2018-12-10Initialize binnobu
* 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
2018-12-07Adjust reserved hash valuesnobu
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
2018-12-07Should use the proper constantnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03make `RARRAY_PTR_USE` more conservertive.ko1
* include/ruby/ruby.h: de-transient at `RARRAY_PTR_USE` and `RARRAY_PTR_USE_START`. Introduce `RARRAY_PTR_USE_TRANSIENT` and `RARRAY_PTR_USE_START_TRANSIENT` if you don't want to de-transient an array. Generally, it is difficult so C-extension writers should not use them. * array.c: use `RARRAY_PTR_USE_TRANSIENT` if possible. * hash.c: ditto. * enum.c (enum_sort_by): remove `rb_ary_transient_heap_evacuate()` because `RARRAY_PTR_USE` do de-transient. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29clear dst Hash on Hash#replace. [Bug #15358]ko1
* hash.c (linear_copy): solve two issues on `Hash#replace`. (1) fix memory leak (1-1) don't allocate memory if destination already has a memory area. (1-2) free destination memory if src is NULL. (2) clear transient heap flag if src is NULL. [Bug #15358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-15hash.c: cast from double to unsigned is undefinedshyouhei
When a negative double is casted into an unsigned type, that operation is undefined (cf: ISO/IEC 9899:1990 section 6.2.9.3). Recent versions of C kindly footnotes that "The remaindering operation performed when a value of integer type is converted to unsigned type need not be performed when a value of real floating type is converted to unsigned type" (cf: ISO/IEC 9899:1999 section 6.3.1.4 footnote 50). So it is a wrong idea to just cast a double to st_data_t. The intention of the code is commented as "mix the actual float value in". It seems we should do a reinterpret_cast and rule out static_cast. Confirmed this changeset does not affect `make benchmark`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08hash.c: +(-1) is a wrong ideashyouhei
Before this changeset RHASH_ARRAY_SIZE_DEC() was expaneded to include an expression like `RHASH_ARRAY_SIZE+(-1)`. RHASH_ARRAY_SIZE is by definition unsigned int. -1 is signed, of course. Adding a signed and an unsigned value requires the "usual arithmetic conversions" (cf: ISO/IEC 9899:1990 section 6.2.1.5). -1 is converted to 0xFFFF by that. This patch prevents that conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04hash.c: [DOC] add docs for ENV.{filter,filter!}stomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04hash.c: [DOC] fix wrong cross-referencesstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04hash.c: [DOC] add missing `block' in call-seq'sstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04hash.c: [DOC] add docs for Hash#{filter,filter!}stomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04hash.c: [DOC] improve Hash#{select!,keep_if} docsstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-03hash.c: fix typesnobu
* hash.c (RHASH_ARRAY_BOUND_RAW): should be unsigned as well as RHASH_ARRAY_SIZE_RAW. * hash.c (find_entry): return unsigned for the consistency with RHASH_ARRAY_SIZE and RHASH_ARRAY_BOUND. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01introduce USE_TRANSIENT_HEAP to enable/disable theap.ko1
* include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro to enable/disable transient heap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01fix WB miss.ko1
* hash.c (linear_copy): remember a hash object to mark pointing objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31remove '//' style comments.ko1
* hash.c: remove '//' style comments pointed out by the following build log: https://travis-ci.org/ruby/ruby/jobs/448551951 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30fix type.ko1
* internal.h (RHASH_ARRAY_SIZE_RAW): should be `int` because it returns n<=8. * hash.c (RHASH_ARRAY_BOUND_RAW): ditto. * hash.c (RHASH_ARRAY_SIZE_RAW): remove a duplicated definition. * hash.c (linear_keys, linear_values): return `long`. * hash.c (linear_keys): fix initialize expression of `key_end`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* remove trailing spaces, expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30support theap for T_HASH. [Feature #14989]ko1
* hash.c, internal.h: support theap for small Hash. Introduce RHASH_ARRAY (li_table) besides st_table and small Hash (<=8 entries) are managed by an array data structure. This array data can be managed by theap. If st_table is needed, then converting array data to st_table data. For st_table using code, we prepare "stlike" APIs which accepts hash value and are very similar to st_ APIs. This work is based on the GSoC achievement by tacinight <tacingiht@gmail.com> and refined by ko1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-26Fix a condition and just call rb_fstring [Feature #15251]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-26* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-26Simplify conditions [Feature #15251]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-26hash.c: aset deduplicates un-tainted stringnormal
We revisit [Bug #9188] since st.c is much improved since then, and benchmarks against so_k_nucleotide seem to indicate little or no performance change compared to before. [ruby-core:89555] [Feature #15251] From: Anmol Chopra <chopraanmol1@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13hash.c: improve docs for Hash#{merge,merge!,update}stomar
* hash.c: [DOC] improve docs for Hash#{merge,merge!,update}: various rewordings, avoid referring to the receiver as `hsh' (does not appear in the call-seq of the generated HTML docs), mention that Hash#update is an alias for Hash#merge!, use more distinct example values, fix spacing in code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12hash.c: improve docs for Hash#{size,length}stomar
* hash.c: [DOC] shorten example code for Hash#{size,length} and mention aliases at the end; also enable links. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26fallback env encoding to ASCII-8BITnobu
* hash.c (env_enc_str_new): as no locale/filesystem encoding is available in miniruby on Windows, fallback the encoding to ASCII-8BIT so it is valid encoding when the conversion failed. [ruby-core:89177] [Bug #15164] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20Enumerable#to_h with block and so onnobu
[Feature #15143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-19* hash.c (rb_hash_update): fix indentmame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-19* hash.c (rb_hash_update): remove a meticulous explanationmame
As per Marc-Andre's comment. [Refs GH-1951] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-19* hash.c (rb_hash_merge): Accepts zero or more hashes as argumentsmame
Hash#merge, merge!, and update could merge exactly two hashes. Now, they accepts zero or more hashes as arguments so that it can merge hashes more than two. This patch was created by Koki Ryu <liukoki@gmail.com> at Ruby Hack Challenge #5. Thank you! [ruby-core:88970] [Feature #15111] [Fix GH-1951] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13warn unused blocks with Enumerable#all? any? one? none?nobu
[Fix GH-1953] From: Koji Onishi <fursich0@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11hash.c: env block size limit on Windowsnobu
* hash.c (ruby_setenv): do not check environment block size. c.f. https://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx Starting with Windows Vista and Windows Server 2008, there is no technical limitation on the size of the environment block. [ruby-core:88400] [Bug #14979] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-27Include Hash#size in the examplestenderlove
Both methods Hash#length and Hash#size share the same source code in Ruby, but they also share the same documentation. Now when you look at the documentation of Hash#size you only see examples for Hash#length, which is confusing. This commit includes Hash#size in the examples and also remarks that both methods are equivalent to each other. Co-authored-by: Alberto Almagro <alberto.almagro@rakuten.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-19renamed ruby_tz_update as ruby_tz_uptodate_pnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-18reduce tzsetnobu
* time.c (rb_localtime_r): call tzset() only after TZ environment variable is changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23[DOC] Add call signature for {Array,Hash}#any?ktsj
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-08rb_ary_dig, rb_hash_dig: nobody is using them outside.shyouhei
mark them static. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e