Граф коммитов

561 Коммитов

Автор SHA1 Сообщение Дата
naruse 5ec23b5222 Updated documentation examples for Hash#value?
The same code is used for has_value? and value?, but according to
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/43765
has_value is deprecated. Use the non-deprecated syntax in the examples.
by Herwin Weststrate <herwin@snt.utwente.nl>
fix https://github.com/ruby/ruby/pull/1491

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-10 18:34:07 +00:00
nobu f2b6e9f05f hash.c: hash should be long
* hash.c (any_hash): should return `long', because ruby assumes
  the hash value of the object id of an object is `long'.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-07 04:25:50 +00:00
nobu 5714a26b90 switching hash removal
* st.h (struct st_hash_type): Remove strong_hash.
  (struct st_table): Remove inside_rebuild_p and curr_hash.
* st.c (do_hash): Use type->hash instead of curr_hash.
  (make_tab_empty): Remove setting up curr_hash.
  (st_init_table_with_size): Remove setting up inside_rebuild_p.
  (rebuild_table): Remove clearing inside_rebuild_p.
  (reset_entry_hashes, HIT_THRESHOULD_FOR_STRONG_HASH): Remove code
  recognizing a denial attack and switching to strong hash.
* hash.c (rb_dbl_long_hash, rb_objid_hash, rb_ident_hash): Use
  rb_hash_start to randomize the hash.
  (str_seed): Remove.
  (any_hash): Remove strong_p and use always rb_str_hash for
  strings.
  (any_hash_weak, rb_any_hash_weak): Remove.
  (st_hash_type objhash): Remove rb_any_hash_weak.

based on the patch by Vladimir N Makarov <vmakarov@redhat.com> at
[ruby-core:78490].  [Bug #13002]

* test/ruby/test_hash.rb (test_wrapper): objects other than special
  constants should be able to be wrapped.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 04:43:48 +00:00
nobu 1e95f9da88 remove unnecessary variable
* st.c (do_hash): remove unnecessary variable and cast.

* hash.c, numeric.c, st.c: adjust style and indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 03:36:52 +00:00
kazu 9fa8006a01 Cleanup ruby method definitions in hash.c
Always add a space between a comma and the next element. These spaces
were there sometimes, but not always. This keeps to code consistent.

Patch by: Herwin Weststrate <herwin@snt.utwente.nl>

[ruby-core:78297] [Misc #12977] [GH-1492]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-03 11:18:44 +00:00
nobu ba8006533c add cast
* hash.c (rb_objid_hash): need to cast down.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-07 03:28:57 +00:00
ko1 75775157ea Introduce table improvement by Vladimir Makarov <vmakarov@redhat.com>.
[Feature #12142]
	See header of st.c for improvment details.

	You can see all of code history here:
	<https://github.com/vnmakarov/ruby/tree/hash_tables_with_open_addressing>

	This improvement is discussed at
	<https://bugs.ruby-lang.org/issues/12142>
	with many people, especially with Yura Sokolov.

	* st.c: improve st_table.

	* include/ruby/st.h: ditto.

	* internal.h, numeric.c, hash.c (rb_dbl_long_hash): extract a function.

	* ext/-test-/st/foreach/foreach.c: catch up this change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-07 00:45:00 +00:00
nobu 4e44f6ef86 [DOC] replace Fixnum with Integer [ci skip]
* numeric.c: [DOC] update document for Integer class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-26 06:11:23 +00:00
nobu 4154b96068 hash.c: fix Hash#compact! return value
* hash.c (rb_hash_compact_bang): should return nil if no elements
  is deleted.  [ruby-core:77709] [Bug #12863]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-22 09:52:35 +00:00
nobu bbd58fa2b9 hash.c: add compact and compact! methods
* hash.c (rb_hash_compact, rb_hash_compact_bang): Removes nil
  values from the original hash, to port Active Support behavior.
  [Feature #11818]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-13 08:06:00 +00:00
usa c2dd2d268e * internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
a hash value of Object might be Bignum, but it causes many troubles
  expecially the Object is used as a key of a hash.  so I've gave up
  to do so.

* array.c (rb_ary_hash): use above macro.

* bignum.c (rb_big_hash): ditto.

* hash.c (rb_obj_hash, rb_hash_hash): ditto.

* numeric.c (rb_dbl_hash): ditto.

* proc.c (proc_hash): ditto.

* re.c (rb_reg_hash, match_hash): ditto.

* string.c (rb_str_hash_m): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-04 16:25:01 +00:00
ngoto c1dbcf9b7e * hash.c (each_pair_i_fast): Fix compile error with old version of
fcc on Solaris 10. [Bug #12768] [ruby-dev:49808]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-16 12:20:35 +00:00
naruse d51aea54d8 * hash.c (each_pair_i_fast): use rb_yield_values2 to avoid var args.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-13 22:22:14 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
mrkn eaa0a27f61 hash.c: map_v -> transform_values
* 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
2016-09-08 02:33:18 +00:00
nobu b22b725c5d util.h: POSIX-noncompliant setenv
* 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
2016-09-07 08:50:39 +00:00
mrkn ea5184b939 hash.c: implement Hash#map_v and Hash#map_v!
* 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
2016-08-09 08:54:15 +00:00
nobu e70df3a701 hash.c: env_name_new
* 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
2016-08-05 15:39:46 +00:00
usa 549605c15d * hasn.c (env_str_new): taint the string. get rid of a test failure
introduced at r55811.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-05 14:19:26 +00:00
nobu cb0cde7f24 hash.c: call w32_getenv pointer
* 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
2016-08-05 08:04:04 +00:00
nobu 9e1b9b9c8f hash.c: set encoding
* 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
2016-08-04 02:54:32 +00:00
nobu c463366dfd rb_funcallv
* *.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
2016-07-29 11:57:14 +00:00
nobu aa0e51b529 hash.c: rb_hash_add_new_element
* 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
2016-07-20 08:35:25 +00:00
nobu 2667d1b38f hash.c: ensure NUL-terminated for ENV
* 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
2016-06-10 05:48:38 +00:00
usa 62b6e90d58 * cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4
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
2016-05-01 11:42:41 +00:00
nobu a19b53aeab hash.c: dry up code
* 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
2016-04-28 08:03:19 +00:00
nobu 2f6821a7c4 hash.c: init table with size
* 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
2016-03-30 08:21:18 +00:00
mrkn f8e79c84a9 * bignum.c (rb_big_hash): make it public function to be available in
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
2016-03-18 01:22:38 +00:00
nobu 2d3a6ba66d hash.c: COPY_DEFAULT
* 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
2016-03-09 07:17:04 +00:00
nobu e684069042 hash.c: SET_PROC_DEFAULT
* 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
2016-03-09 07:17:03 +00:00
nobu 7522e06424 hash.c: SET_DEFAULT
* 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
2016-03-09 07:17:03 +00:00
nobu 921d6e269d hash.c: hash_dup for rb_hash_to_h
* 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
2016-03-09 07:17:02 +00:00
nobu 865a326da9 hash.c: make duplicated hash WB protected
* 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
2016-03-09 07:17:01 +00:00
nobu d000891e43 hash.c: tbl_update_func
* 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
2016-03-09 04:45:27 +00:00
akr f061d40326 * hash.c (rb_hash_invert): [DOC] more examples.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-13 12:45:59 +00:00
nobu b14ea7d05b hash.c: exception examples
* 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
2016-01-27 07:30:42 +00:00
nobu 39cf3780e5 hash.c: trivial optimization
* 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
2016-01-14 02:15:00 +00:00
ngoto cef1f23e89 * gc.c: Delete excess semicolon after RUBY_ALIAS_FUNCTION().
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
2015-12-15 14:20:27 +00:00
normal e52b3a0e2c hash.c (rb_num_hash_start): avoid pathological behavior
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
2015-12-11 08:23:46 +00:00
nobu 165e10b6cf compile.c: rehash cdhash
* 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
2015-12-11 02:38:20 +00:00
marcandre cb3b463a50 * array.c: Improve and fix documentation for Array#dig
[#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
2015-12-08 05:21:11 +00:00
nobu f534bc2ed9 hash.c: fix rubyspec failure
* 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
2015-12-06 12:13:25 +00:00
nobu 5e3467c441 hash.c: env encoding fallback on Windows
* 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
2015-12-05 08:26:26 +00:00
nobu 0701e5ff46 update rdoc of dig methods [ci skip]
* 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
2015-11-17 02:25:28 +00:00
nobu 59a3fe5846 hash.c: compare methods [ci skip]
* 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
2015-11-14 08:13:11 +00:00
nobu 56e3b49304 sprintf.c: nil value is valid
* 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
2015-11-11 09:30:31 +00:00
nobu 16e7869ded hash.c: use rb_func_proc_new
* 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
2015-11-10 09:25:58 +00:00
nobu fbe967ec02 hash.c: to_proc
* 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
2015-11-10 07:57:17 +00:00
nobu d68c3ecf98 hash.c: compare methods
* 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
2015-11-10 05:02:02 +00:00
nobu 29862685c0 dig
* 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
2015-11-09 12:27:26 +00:00