aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
Commit message (Collapse)AuthorAgeFilesLines
* replace fixnum by integer in documents.akr2016-09-081-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: map_v -> transform_valuesmrkn2016-09-081-19/+19
| | | | | | | | | | * hash.c (rb_hash_transform_values, rb_hash_transform_values_bang): Rename map_v to transform_values. [Feature #12512] [ruby-core:76095] * test/ruby/test_hash.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* util.h: POSIX-noncompliant setenvnobu2016-09-071-2/+0
| | | | | | | * include/ruby/util.h (setenv): remove POSIX-noncompliant definition with 2 arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: implement Hash#map_v and Hash#map_v!mrkn2016-08-091-0/+67
| | | | | | | | | * hash.c (rb_hash_map_v, rb_hash_map_v_bang): impelement Hash#map_v and Hash#map_v! [Feature #12512] [ruby-core:76095] * test/ruby/test_hash.rb: add tests for above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: env_name_newnobu2016-08-051-21/+32
| | | | | | | | | * hash.c (env_enc_str_new): make string for an environment variable name or value. * hash.c (env_name_new): make environment value string with the encoding for its name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hasn.c (env_str_new): taint the string. get rid of a test failureusa2016-08-051-0/+1
| | | | | | | introduced at r55811. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: call w32_getenv pointernobu2016-08-051-8/+12
| | | | | | | * hash.c (w32_getenv): call rb_w32_getenv and rb_w32_ugetenv via this pointer without further comparisons. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: set encodingnobu2016-08-041-1/+1
| | | | | | | * hash.c (env_assoc): the encoding of the value should be the locale, as well as other methods, [], fetch, values, etc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rb_funcallvnobu2016-07-291-2/+2
| | | | | | | * *.c: rename rb_funcall2 to rb_funcallv, except for extensions which are/will be/may be gems. [Fix GH-1406] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: rb_hash_add_new_elementnobu2016-07-201-0/+24
| | | | | | | | | * hash.c (rb_hash_add_new_element): add new element or do nothing if it is contained already. * array.c (ary_add_hash, ary_add_hash_by): use rb_hash_add_new_element. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: ensure NUL-terminated for ENVnobu2016-06-101-1/+1
| | | | | | | | | * hash.c (get_env_cstr): ensure NUL-terminated. [ruby-dev:49655] [Bug #12475] * string.c (rb_str_fill_terminator): return the pointer to the NUL-terminated content. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4usa2016-05-011-1/+1
| | | | | | | | support leftovers. [fix GH-1328] patched by @cremno git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: dry up codenobu2016-04-281-4/+2
| | | | | | | * hash.c (rb_hash_update_{block,func}_callback): dry up hash update callback code. [Fix GH-1338] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: init table with sizenobu2016-03-301-0/+3
| | | | | | | * hash.c (rb_hash_s_create): allocate internal table with the given size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * bignum.c (rb_big_hash): make it public function to be available inmrkn2016-03-181-0/+4
| | | | | | | | | | | | | other source files, and remove documentation comment for Bignum#hash. * bignum.c (Bignum#hash): remove its definition because it is unified with Object#hash. * include/ruby/intern.h (rb_big_hash): add a prototype declaration. * hash.c (any_hash): treat Bignum values directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: COPY_DEFAULTnobu2016-03-091-8/+12
| | | | | | * hash.c (COPY_DEFAULT): new macro to copy the default value/proc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: SET_PROC_DEFAULTnobu2016-03-091-11/+14
| | | | | | * hash.c (SET_PROC_DEFAULT): new macro to set the default proc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: SET_DEFAULTnobu2016-03-091-4/+6
| | | | | | * hash.c (SET_DEFAULT): new macro to set the default value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: hash_dup for rb_hash_to_hnobu2016-03-091-8/+2
| | | | | | | * hash.c (rb_hash_to_h): share hash_dup to copy the contents and the default value/proc only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: make duplicated hash WB protectednobu2016-03-091-19/+22
| | | | | | | | | | | | | * hash.c (hash_alloc_flags): allocate new hash with the flags and the default value. * hash.c (hash_dup): duplicate with the flags and the default value. * hash.c (rb_hash_dup): make the duplicated hash write-barrier protected. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: tbl_update_funcnobu2016-03-091-1/+3
| | | | | | | * hash.c (tbl_update_func): extract function typedef from the declaration of tbl_update. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c (rb_hash_invert): [DOC] more examples.akr2016-02-131-0/+16
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: exception examplesnobu2016-01-271-0/+2
| | | | | | * hash.c (rb_hash_dig): [DOC] add examples of exceptions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: trivial optimizationnobu2016-01-141-6/+2
| | | | | | | * hash.c (rb_hash_initialize_copy): trivial optimization, copy HASH_PROC_DEFAULT bit directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * gc.c: Delete excess semicolon after RUBY_ALIAS_FUNCTION().ngoto2015-12-151-5/+5
| | | | | | | | | | Suppress "syntax error: empty declaration" warnings by Oracle Solaris Studio 12.x on Solaris. [Bug #11821] * hash.c: ditto, after NOINSERT_UPDATE_CALLBACK(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c (rb_num_hash_start): avoid pathological behaviornormal2015-12-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The OR-ing itself is bad for a hash function, and shifting 3 bits left was not enough to undo the damage done by shifting (RUBY_SPECIAL_SHIFT+3) bits right. Experimentally, shifting 16-17 bits seemed to work well in preparing the number for murmur hash. Add a few more benchmarks to based on bm_hash_shift to ensure we don't hurt performance too much with tweaks. I'm pretty confident about this change and commiting it now; especially since we're still using Murmur behind it (but perhaps we can update to a newer hash from Murmur...) [ruby-core:72028] [Feature #11405] target 0: a (ruby 2.3.0dev (2015-12-11 trunk 53027) [x86_64-linux]) at "/home/ew/rrrr/b/ruby" target 1: b (ruby 2.3.0dev (2015-12-11 master 53027) [x86_64-linux]) at "/home/ew/ruby/b/ruby" benchmark results: minimum results in each 5 measurements. Execution time (sec) name a b hash_aref_dsym 0.279 0.276 hash_aref_dsym_long 4.951 4.936 hash_aref_fix 0.281 0.283 hash_aref_flo 0.060 0.060 hash_aref_miss 0.409 0.410 hash_aref_str 0.387 0.385 hash_aref_sym 0.275 0.270 hash_aref_sym_long 0.410 0.411 hash_flatten 0.252 0.237 hash_ident_flo 0.035 0.032 hash_ident_num 0.254 0.251 hash_ident_obj 0.252 0.256 hash_ident_str 0.250 0.252 hash_ident_sym 0.259 0.270 hash_keys 0.267 0.267 hash_shift 0.016 0.015 hash_shift_u16 0.074 0.072 hash_shift_u24 0.071 0.071 hash_shift_u32 0.073 0.072 hash_to_proc 0.008 0.008 hash_values 0.263 0.264 Speedup ratio: compare with the result of `a' (greater is better) name b hash_aref_dsym 1.009 hash_aref_dsym_long 1.003 hash_aref_fix 0.993 hash_aref_flo 1.001 hash_aref_miss 0.996 hash_aref_str 1.006 hash_aref_sym 1.017 hash_aref_sym_long 0.998 hash_flatten 1.061 hash_ident_flo 1.072 hash_ident_num 1.012 hash_ident_obj 0.987 hash_ident_str 0.993 hash_ident_sym 0.959 hash_keys 0.997 hash_shift 1.036 hash_shift_u16 1.039 hash_shift_u24 1.001 hash_shift_u32 1.017 hash_to_proc 1.001 hash_values 0.995 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: rehash cdhashnobu2015-12-111-1/+1
| | | | | | | | * compile.c (iseq_compile_each, ibf_load_object_hash): rehash case-dispatch hash to reduce collisions. http://d.hatena.ne.jp/ku-ma-me/20151210 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c: Improve and fix documentation for Array#digmarcandre2015-12-081-3/+7
| | | | | | | | | | | | [#11776] * hash.c: ditto * struct.c: ditto * test_hash.rb: Add basic test for user defined `dig`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: fix rubyspec failurenobu2015-12-061-5/+3
| | | | | | | | * hash.c (env_fetch): yield coerced string. * hash.c (env_assoc): return coerced string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: env encoding fallback on Windowsnobu2015-12-051-17/+63
| | | | | | | | | | * hash.c (env_str_new, env_path_str_new): make default string UTF-8 for the case conversion is not possible. [Bug #8822] * hash.c (get_env_cstr): convert non-ASCII string to UTF-8 string. * hash.c (ruby_setenv): use wide char version to put environment variable to deal with non-ASCII value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* update rdoc of dig methods [ci skip]nobu2015-11-171-2/+2
| | | | | | | | * array.c (rb_ary_dig), hash.c (rb_hash_dig): [DOC] Update comments describing dig methods. [Fix GH-1103] * struct.c (rb_struct_dig): [DOC] add rdoc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: compare methods [ci skip]nobu2015-11-141-0/+52
| | | | | | * hash.c (rb_hash_{le,lt,ge,gt}): [DOC] for [Feature #10984] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: nil value is validnobu2015-11-111-4/+4
| | | | | | | | * sprintf.c (rb_str_format): look up the key, then get default value and raise KeyError if the returned value is nil. [ruby-dev:49338] [Ruby trunk - Bug #11677] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: use rb_func_proc_newnobu2015-11-101-2/+3
| | | | | | | * hash.c (rb_hash_to_proc): use rb_func_proc_new to make light weight proc. [Feature #11653] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: to_procnobu2015-11-101-0/+13
| | | | | | | * hash.c (rb_hash_to_proc): new method Hash#to_proc. [Feature #11653] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: compare methodsnobu2015-11-101-0/+57
| | | | | | | | | * hash.c (rb_hash_{le,lt,ge,gt}): new methods, Hash#<=, Hash#<, Hash#>=, Hash#>, to test if all elements of a hash are also included in another hash, and vice versa. [ruby-core:68561] [Feature #10984] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dignobu2015-11-091-0/+24
| | | | | | | | | * array.c (rb_ary_dig): new method Array#dig. * hash.c (rb_hash_dig): new method Hash#dig. * object.c (rb_obj_dig): dig in nested arrays/hashes. [Feature #11643] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: fix oob accessnobu2015-11-081-3/+4
| | | | | | | * hash.c (rb_hash_default): do not access argv when no arguments is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c: use correct grammer. Patch by @tveastmanhsbt2015-11-041-1/+1
| | | | | | [fix GH-1079][ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* RUBY_DTRACE_CREATE_HOOKnobu2015-10-291-3/+1
| | | | | | | | | | * internal.h (RUBY_DTRACE_CREATE_HOOK): macro to call hook at object creation. * vm.c (rb_source_location, rb_source_loc): retrieve source path and line number at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: GC guardsnobu2015-09-251-0/+2
| | | | | | | * hash.c (env_delete, env_aset): prevent environment variable names from GC while ruby_setenv. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: [DOC] orders do not matter [ci skip]nobu2015-09-041-0/+7
| | | | | | | * hash.c (rb_hash_equal, rb_hash_eql): [DOC] the orders of each hashes are not compared. [Bug #11508] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: improve integer/fixnum hashingnormal2015-08-141-14/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The low bits of Ruby object IDs are rarely populated in the current implementation, so ensure the get used. Early versions of this patch redundantly shifted static symbols in any_hash, causing regresions with static symbols in hash_aref_sym * hash.c (any_hash): skip rb_objid_hash for static syms (rb_num_hash_start): extract from rb_ident_hash (rb_objid_hash): call rb_num_hash_start (rb_ident_hash): ditto [ruby-core:70181] [Feature #11405] target 0: a (ruby 2.3.0dev (2015-07-30 trunk 51437) [x86_64-linux] target 1: b (ruby 2.3.0dev (2015-07-30 patch 51437) [x86_64-linux] benchmark results from Xeon E3-1230 v3 @ 3.30GHz (turbo disabled): minimum results in each 10 measurements. Execution time (sec) name a b hash_aref_dsym 0.316 0.300 hash_aref_dsym_long 5.106 5.063 hash_aref_fix 0.304 0.297 hash_aref_flo 0.061 0.060 hash_aref_miss 0.433 0.430 hash_aref_str 0.408 0.396 hash_aref_sym 0.312 0.306 hash_aref_sym_long 0.482 0.469 hash_flatten 0.385 0.273 hash_ident_flo 0.036 0.037 hash_ident_num 0.277 0.276 hash_ident_obj 0.291 0.284 hash_ident_str 0.289 0.286 hash_ident_sym 0.285 0.281 hash_keys 0.269 0.271 hash_shift 0.020 0.016 hash_values 0.264 0.264 loop_whileloop2 0.101 0.099 vm2_bighash* 3.066 2.972 Speedup ratio: compare with the result of `a' (greater is better) name b hash_aref_dsym 1.052 hash_aref_dsym_long 1.008 hash_aref_fix 1.024 hash_aref_flo 1.015 hash_aref_miss 1.007 hash_aref_str 1.031 hash_aref_sym 1.018 hash_aref_sym_long 1.027 hash_flatten 1.410 hash_ident_flo 0.994 hash_ident_num 1.001 hash_ident_obj 1.022 hash_ident_str 1.012 hash_ident_sym 1.016 hash_keys 0.992 hash_shift 1.237 hash_values 1.001 loop_whileloop2 1.013 vm2_bighash* 1.032 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c: [DOC] Improve description of symbol key syntaxzzak2015-08-071-1/+1
| | | | | | | | Patch by Raphael Das Gupta in documenting-ruby/ruby#51: https://github.com/documenting-ruby/ruby/pull/51 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: fix dynamic symbol hash valuenobu2015-07-291-1/+1
| | | | | | | * hash.c (any_hash), symbol.c (dsymbol_alloc): fix dynamic symbol hash value by restricting in Fixnum range, that is `long`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: move rb_obj_hashnobu2015-07-291-18/+28
| | | | | | * hash.c (rb_obj_hash): move in order to share with rb_any_hash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: fix symbol hashnobu2015-07-291-0/+15
| | | | | | | * hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: fix float hashnobu2015-07-291-2/+4
| | | | | | | * hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.h: memoize hashval for RSymbolnormal2015-07-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | This speeds up the hash function for dynamic symbols. [ruby-core:70129] [Bug #11396], nearly up to Ruby 2.1 levels Power-of-two hash sizing [Feature #9425] speeds up cases where we have a good hash, but this means we can no longer hide behind weak hashes. Unfortunately, object IDs do not hash well, but we may use the extra space in the RSymbol struct to memoize the hash value. Further optimizations should be possible. For now, the st.c APIs force us to calculate rb_str_hash redundantly at dsym registration. * symbol.h (struct RSymbol): add hashval field * symbol.c (dsymbol_alloc): setup hashval field once * hash.c (rb_any_hash): return RSymbol->hashval directly * common.mk: hash.o depends on symbol.h Thanks to Bruno Escherl <bruno@escherl.net> for the bug report [ruby-core:70129] [Bug #11396] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c (enum_minmax): simplify return value creationnormal2015-06-251-5/+10
| | | | | | | | | | | | | | No need to call three functions on success when one will do. This results in less LoC and smaller object code, too: text data bss dec hex filename 33860 0 296 34156 856c gcc/enum.o-before 33852 0 296 34148 8564 gcc/enum.o * enum.c (enum_minmax): simplify return value creation * test/ruby/test_enum.rb: test behavior on empty git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e