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

458 Коммитов

Автор SHA1 Сообщение Дата
normal ef59670a44 st.c: use power-of-two sizes to avoid slow modulo ops
* st.c (hash_pos): use bitwise AND to avoid slow modulo op
  (new_size): power-of-two sizes for hash_pos change
  (st_numhash): adjust for common keys due to lack of prime modulo
  [Feature #9425]
* hash.c (rb_any_hash): right shift for symbols
* benchmark/bm_hash_aref_miss.rb: added to show improvement
* benchmark/bm_hash_aref_sym_long.rb: ditto
* benchmark/bm_hash_aref_str.rb: ditto
* benchmark/bm_hash_aref_sym.rb: ditto
* benchmark/bm_hash_ident_num.rb: added to prevent regression
* benchmark/bm_hash_ident_obj.rb: ditto
* benchmark/bm_hash_ident_str.rb: ditto
* benchmark/bm_hash_ident_sym.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-22 23:34:21 +00:00
nobu fc23374f06 [DOC] add links to `Object#hash`
add links to `Object#hash` to each #`hash` methods rdocs.
[Fixes GH-567]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:43 +00:00
nobu 1f29e8e2ba class.c: do nothing if copying self
* class.c (rb_mod_init_copy): do nothing if copying self.
  [ruby-dev:47989] [Bug #9535]
* hash.c (rb_hash_initialize_copy): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-21 11:42:03 +00:00
glass 13834fb3cb * hash.c (rb_hash_flatten): fix behavior of flatten(0).
[ruby-dev:47988] [Bug #9533]

* test/ruby/test_array.rb: test for above. patch is from
  Takeshi Sasaki.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-20 03:09:13 +00:00
glass f138018e9e * hash.c (rb_hash_flatten): fix behavior of flatten(-1).
[ruby-dev:47988] [Bug #9533]

* test/ruby/test_array.rb: test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-20 02:27:30 +00:00
tmm1 58f800a278 insns.def: add opt path for Hash#[] and Hash#[]= used with str literal keys
* insns.def (opt_aref_with): new instruction to optimize Hash#[],
  removing any allocation overhead when used with a string literal
  key. Patch by normalperson (Eric Wong). [ruby-core:59640] [Bug #9382]
* insns.def (opt_aset_with): new instruction to optimize Hash#[]=
* compile.c (iseq_compile_each): compiler shortcuts for new
  instructions
* hash.c (static VALUE rb_hash_compare_by_id_p): fix documentation for
  Hash#compare_by_identity to reflect frozen string sharing
* test/ruby/test_hash.rb (class TestHash): test for new behavior

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-10 04:54:08 +00:00
usa ac2864a871 * hash.c (rb_objid_hash): should return `long'. brushup r44534.
* object.c (rb_obj_hash): follow above change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 11:34:17 +00:00
usa 8abc55bc54 * hash.c (rb_any_hash): should treat the return value of rb_objid_hash()
as `long', because ruby assumes the object id of an object is `long'.
  this fixes test failures on mswin64 introduced at r44525.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 08:42:42 +00:00
nobu ab6efa5be2 object.c: hash value from objid with salt
* hash.c (rb_objid_hash): return hash value from object ID with a
  salt, extract from rb_any_hash().
* object.c (rb_obj_hash): return same value as rb_any_hash().
  fix r44125.  [ruby-core:59638] [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-08 06:55:24 +00:00
glass 2c11bda8b9 * hash.c (rb_hash_keys): make rb_hash_keys() static.
it is no longer used from array.c since r43969.
  the patch is from normalperson (Eric Wong).
  [ruby-core:59449] [Feature #9336]

* internal.h: remove definition of rb_hash_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-01 15:19:23 +00:00
nobu 4ce4f43f91 hash.c: remove dead code
* hash.c (rb_hash_reject): remove dead code for the deprecated
  behavior.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-26 05:28:24 +00:00
nobu 3a247f6489 hash.c: no extra states copy
* hash.c (HASH_REJECT_COPY_EXTRA_STATES): turn off the old
  behavior, copying extra states by accident.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-26 05:25:08 +00:00
nobu af17af1faa hash.c: extra states
* hash.c (rb_hash_reject): use words "extra states".


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-24 01:13:40 +00:00
nobu bc159ec502 hash.c: fix infinite loop
* hash.c (has_extra_methods): traverse ancestors, and fix infinite
  loop.  [Bug #9275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 09:01:05 +00:00
nobu cb62186b07 hash.c: fix commit miss
* hash.c (HAS_EXTRA_STATES): remove extra parenthesis.
  [Bug #9275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 07:00:01 +00:00
nobu c25c84777c hash.c: reduce warning
* hash.c (HAS_EXTRA_STATES): warn extra states only when something
  differ.  [ruby-core:59254] [Bug #9275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 06:53:51 +00:00
nobu 21e74f5481 hash.c: reword
* hash.c (HAS_EXTRA_STATES, rb_hash_reject): use words
  "extra states".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 06:53:17 +00:00
ko1 c702005a7b * include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
  proc.c, process.c, re.c, string.c, variable.c, vm.c,
  vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
  vm_method.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 08:07:47 +00:00
nobu 571955c13f hash.c: revert
* hash.c (rb_hash_reject): revert to deprecated behavior, with
  warnings, due to compatibility for HashWithDifferentAccess.
  [ruby-core:59154] [Bug #9223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-17 11:15:00 +00:00
nobu cf460c34f7 hash.c: add warnings
* hash.c (rb_hash_reject): warn attributes in detail more.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-17 11:01:37 +00:00
nobu 26e425e6f4 hash.c: typo
* hash.c (rb_hash_reject): fix typo in macro name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 14:36:14 +00:00
nobu 0988148782 hash.c: warnings in rb_hash_reject
* hash.c (rb_hash_dup_empty): split from rb_hash_dup.

* hash.c (rb_hash_reject): add warnings (currently suppressed).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 13:40:04 +00:00
nobu 6cd0d06bae hash.c: refactor loop
* hash.c (rb_hash): rewrite with while instead of goto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 13:40:02 +00:00
nobu 740535f843 hash.c: reject should return a plain hash
* hash.c (rb_hash_reject): return a plain hash, without copying
  the class, default value, instance variables, and taintedness.
  they had been copied just by accident.
  [ruby-core:59045] [Bug #9223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-11 07:01:29 +00:00
nobu 037a9d0655 array.c, hash.c: add salt
* array.c (rb_ary_hash): add salt to differentiate false and empty
  array.  [ruby-core:58993] [Bug #9231]
* hash.c (rb_any_hash, rb_hash_hash): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 14:44:51 +00:00
tmm1 a111923062 hash.c: fix segv in Hash#replace
* hash.c (rb_hash_replace): fix segv on `{}.replace({})` introduced
  in r44060 [Bug #9230] [ruby-core:58991]
* test/ruby/test_hash.rb: regression test for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-09 10:06:49 +00:00
nobu cf85aaf83e hash.c: reject shoult infect
* hash.c (rb_hash_reject): result should be infected by the
  receiver.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 11:25:06 +00:00
tmm1 3dd248f13d hash.c: fix WB miss issue in Hash#replace
* hash.c (rb_hash_replace): add a write barrier to fix GC mark miss on
  hashes using Hash#replace [Bug #9226] [ruby-core:58948]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 03:03:42 +00:00
tmm1 779ae78995 hash.c: revert r43870 and add alternative parser patch for literal keys
* hash.c (hash_aset_str): revert r43870 due to performance issue
  [Bug #9188] [ruby-core:58730]
* parse.y (assoc): convert literal string hash keys to fstrings
* test/ruby/test_hash.rb (class TestHash): expand test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 01:52:28 +00:00
nobu 7416073cde hash.c: rb_hash_reject without dup
* hash.c (rb_hash_reject): copy unrejected elements only to new hash,
  so that the change on the original receiver can affect.
  [ruby-core:58914] [Bug #9223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-07 02:16:04 +00:00
nobu 1bbc52dee1 hash.c: bail out to the outermost frame
* hash.c (rb_hash): revert r43981 and bail out to the outermost frame
  when recursion is detected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 05:40:43 +00:00
nobu 218d1f5e1e hash.c: same hash value for similar constructs
* hash.c (rb_hash_recursive): make similar (recursive) constructs
  return same hash value.  execute recursively, and rewind to the
  topmost frame with an object which .eql? to the recursive
  object, if recursion is detected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 13:32:24 +00:00
nobu 6f2efe84fb hash.c: detect recursion for all
* hash.c (rb_hash): detect recursion for all `hash' methods.  each
  `hash' methods no longer need to use rb_exec_recursive().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 13:18:30 +00:00
glass 437b8bc53b * array.c (rb_hash_rehash): use hash_alloc() instead of rb_hash_new().
[Bug #9187]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 11:19:06 +00:00
nobu d7de38ff62 * hash.c (w32_getenv): should be static.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 03:18:46 +00:00
usa ff9f9c6d84 * hash.c (getenv): fixed test failures introduced by r43950.
[ruby-core:58774] [Bug #9195] reported by phasis68 (Heesob Park).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-02 13:31:14 +00:00
glass ead0c5d356 * hash.c (rb_hash_rehash): make temporary st_table under the control
of GC. [Bug #9187]

* test/ruby/test_hash.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-02 12:59:31 +00:00
usa 6b1a58b9e6 * hash.c (getenv): use ANSI codepage version of getenv() for miniruby
on Windows.
  [ruby-core:58732] [Bug #9189] reported by phasis68 (Heesob Park).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-01 15:55:56 +00:00
glass 8efbe96231 * hash.c (rb_hash_to_a): specify array capa.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-01 05:39:38 +00:00
glass bfbe1b9b31 * hash.c (rb_hash_rehash): fix to free new st_table when exception
is raised in do_hash(). [Bug #9187]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-01 05:28:54 +00:00
glass 79e6336495 * st.c: add st_values() and st_values_check().
* include/ruby/st.h: add prototypes for above.

* hash.c (rb_hash_values): use st_values_check() for performance
 improvement if VALUE and st_data_t are compatible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 08:39:16 +00:00
glass 78cfcbc657 * st.c (st_keys): fix not to use Qundef in st.c.
* include/ruby/st.h: define modified prototype.

* hash.c (rb_hash_keys): use modified st_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 08:15:26 +00:00
glass 8c91dfb91b * st.c (st_keys): fix to use st_index_t for size of hash.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 16:36:44 +00:00
glass b426e1b1fa * st.c (st_keys): define st_keys(). it writes each key to buffer.
* hash.c (rb_hash_keys): use st_keys() for performance improvement
  if st_data_t and VALUE are compatible.

* st.h: define macro ST_DATA_COMPATIBLE_P() to predicate whether
  st_data_t and passed type are compatible.

* configure.in: check existence of builtin function to use in
  ST_DATA_COMPATIBLE_P().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 16:07:10 +00:00
tmm1 23178d1044 * gc.c (gc_page_sweep): Fix compile warning from last commit.
* hash.c (hash_aset_str): Re-use existing variable to avoid
  unnecessary pointer dereferencing.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 06:24:37 +00:00
tmm1 0c3b3e9237 * hash.c (hash_aset_str): Use rb_fstring() to de-duplicate hash string
keys. Patch by Eric Wong. [Bug #8998] [ruby-core:57727]
* test/ruby/test_hash.rb (class TestHash): test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 05:28:55 +00:00
nobu 94f01c55df should not ignore the rest of recursive constructs
* array.c (rb_ary_hash): should not ignore the rest of recursive
  constructs.
* hash.c (rb_hash_hash): ditto.
* range.c (range_hash): ditto.
* struct.c (rb_struct_hash): ditto.
* test/-ext-/test_recursion.rb (TestRecursion): separate from
  test/ruby/test_thread.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 17:20:16 +00:00
nobu d503381ce8 hash.c: cut off if recursion
* hash.c (rb_hash): cut off if recursion detected to get rid of stack
  overflow.  [ruby-core:58567] [Bug #9151]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 13:43:40 +00:00
nobu abdada2d85 hash.c: static internal functions
* hash.c (NOINSERT_UPDATE_CALLBACK): make both of noinsert and insert
  internal functions static.  and put semicolons for etags to find the
  following functions properly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-17 14:34:27 +00:00
tarui 28a1c4f33e * cont.c : Introdule ensure rollback mechanism. Please see below.
* internal.h (ruby_register_rollback_func_for_ensure): catch up above change.
	  Add rollback mechanism API.

	* vm_core.h (typedef struct rb_vm_struct): catch up above change.
	  Introdule ensure-rollback relation table.

	* vm_core.h (typedef struct rb_thread_struct): catch up above change.
	  Introdule ensure stack.

	* eval.c (rb_ensure): catch up above change.
	  Introdule ensure stack.

	* hash.c : New function for rollback ensure, and register it to
	  ensure-rollback relation table. [ruby-dev:47803] [Bug #9105]

	Ensure Rollback Mechanism:
	A rollback's function is a function to rollback a state before ensure's
	function execution.
	When the jump of callcc is across the scope of rb_ensure,
	ensure's functions and rollback's functions are executed appropriately
	for keeping consistency.

	Current API is unstable, and only internal use.

	ruby_register_rollback_func_for_ensure(ensure_func,rollback_func)
	This API create relation ensure's function to rollback's function.
	By registered rollback's function, it is executed When jumpping into
	corresponding rb_ensure scope.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-15 17:15:31 +00:00