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

671 Коммитов

Автор SHA1 Сообщение Дата
nobu a6ba688db3 array.c: array may be modified in the block
* array.c (rb_ary_any_p): the array may be modified in the yielded
  block, do not access directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-18 14:24:48 +00:00
nobu d738e3e155 optimized any? methods
* array.c (rb_ary_any_p), hash.c (rb_hash_any_p): optimized
  versions.  these are bit faster than optimization in
  Enumerable#any?.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-18 13:16:48 +00:00
hsbt 94bbd10ea7 * array.c: Clarify documentation for Array#insert.
[ruby-core:62934] [Bug #9901]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-11 07:00:49 +00:00
nobu e99ee55abc constify parameters
* include/ruby/intern.h: constify `argv` parameters.

* include/ruby/ruby.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-18 06:16:39 +00:00
nobu b654e0719a array.c: non-recursive rcombinate0
* array.c (rcombinate0): remove recursion, by looping with indexes
  stored in `p`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-14 01:55:25 +00:00
nobu 4802149e44 array.c: non-recursive rpermute0
* array.c (rpermute0): remove recursion, by looping with indexes
  stored in `p`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-14 01:55:07 +00:00
nobu 9d6b7aede9 array.c: non-recursive permute0
* array.c (permute0): remove recursion, by looping with indexes
  stored in `p`.  [ruby-core:63103] [Bug #9932]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-14 01:54:45 +00:00
nobu 02725fb682 array.c: combinate0
* array.c (combinate0): extract.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-14 01:54:33 +00:00
nobu 537b4a6422 array.c: combination on a shared copy
* array.c (rb_ary_combination): iterate on a shared copy, and use
  array of indexes instead of array of chosen objects.
  [ruby-core:63149] [Bug #9939]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-13 08:34:17 +00:00
nobu 95bac4f75e array.c: yield_indexed_values
* array.c (yield_indexed_values): extract from permute0(),
  rpermute0(), and rcombinate0().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-13 08:33:58 +00:00
nobu e6f1557562 array.c: fix array size
* array.c (rb_ary_permutation): `p` is the array of size `r`, as
  commented at permute0().  since `n >= r` here, buffer overflow
  never happened, just reduce unnecessary allocation though.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-13 04:43:57 +00:00
zzak f1d6b82981 * array.c: [DOC] Clarify default argument for Array.new.
By @Elffers [Fixes GH-610] [ci skip]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-24 21:30:42 +00:00
hsbt 2091ccac88 * array.c: [DOC] Add more documents to shuffle! and shuffle.
Contributed by @JuanitoFatas [ci skip][fix GH-612]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-24 13:40:28 +00:00
nobu 7f3b12f05b use predefined IDs
* array.c (rb_ary_equal), hash.c (hash_equal): use predefined IDs,
  `to_ary` and `to_hash` respectively.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-20 08:28:31 +00:00
ko1 f2606d6250 * array.c (ARY_SET): added.
ARY_SET() is same functionality of RARRAY_ASET(), but
  it has an assertion (`ary' doesn't have shared array).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-11 09:55:10 +00:00
ko1 6bc463204a * array.c: make shared arrays WB-protected objects.
Shared arrays were WB-unprotected object because
  sharing array can modify shared array's buffer
  if it occupied shared array.
  [sharing array (ary)] -> [shared array (shared)] -> <buff>
                |                                       A
                +---------------------------------------+
             write `buff' with WB(ary, &buff[i], obj)
             -> if `ary' and `shared' are old, then only `ary'
                will be remembered.
             -> traverse from `ary'. But `shared' is old, so
                that written `obj' is not marked.
  It cause WB miss so that shared arrays were WB-unprotected.
  (WB-unprotected objects are marked everytime if it is living)
  This patch insert WB() for `shared' if it is needed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-11 08:47:00 +00:00
nobu 153fa25658 array.c: maybe shared array
* array.c (ary_reject): may be turned into a shared array during
  the given block.  [ruby-dev:48101] [Bug #9727]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-11 03:44:52 +00:00
ko1 f19bf5ba5a * array.c (rb_ary_modify): remember shared array owner if a shared
array owner is promoted and a shared array is not promoted.
  Now, shared array is WB-unprotected so that shared arrays are not
  promoted.  All objects referred from shared array should be marked
  correctly.
  [ruby-core:61919] [ruby-trunk - Bug #9718]
* test/ruby/test_array.rb: add a test for above.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-10 10:16:24 +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 78b1ca9f0f array.c: comment why rb_ary_modify is needed twice
* array.c (rb_ary_initialize): NUM2LONG() may call size.to_int,
  ary can be frozen, modified, etc, so recheck after argument
  conversion is necessary.  [Closes GH-526]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-06 01:31:27 +00:00
marcandre e030b4ee79 * array.c: rdoc clarification for <=>
* file.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 17:33:47 +00:00
tmm1 3cf4fe47e8 array.c: return first unique element in Array#uniq
* array.c (ary_add_hash): Fix consistency issue between Array#uniq and
  Array#uniq! [Bug #9340] [ruby-core:59457]
* test/ruby/test_array.rb (class TestArray): regression test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-06 19:38:20 +00:00
glass 56b0396944 * array.c (rb_ary_zip): use ALLOCV_N() instead of ALLOCA_N().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-01 15:55:51 +00:00
marcandre 9471f4187f * array.c: Have to_h raise on elements that are not key-value pairs [#9239]
* enum.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 03:42:29 +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
ko1 3477670963 * array.c: fix comment to remove the word "shady".
* variable.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-13 02:53:27 +00:00
marcandre e91ccb6c67 * array.c: More doc examples for Array#{map|collect}{!} using both forms
* enum.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-11 19:55:56 +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
nobu 1018f57f2c array.c: id_random
* array.c (rb_ary_shuffle_bang, rb_ary_sample): share id_random
  instead of no longer used sym_random.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 06:47:39 +00:00
ktsj 7f5a9f3881 * array.c (rb_ary_shuffle_bang, rb_ary_sample): rename local variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 05:58:17 +00:00
ktsj 3e1360f370 * array.c (rb_ary_shuffle_bang, rb_ary_sample): check
unknown keywords.

* test/ruby/test_array.rb (test_shuffle, test_sample): tests for
  the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 05:02:12 +00:00
charliesome e0290c9404 * array.c (rb_ary_or): use RHASH_TBL_RAW instead of RHASH_TBL
* process.c (rb_execarg_fixup): use RHASH_TBL_RAW and insert write
  barriers where appropriate

* vm.c (kwmerge_i): use RHASH_TBL_RAW

* vm.c (HASH_ASET): use rb_hash_aset instead of calling directly into
  st_insert

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 00:41:01 +00:00
nobu 19737494b9 array.c: prefer lhs elements
* array.c (rb_ary_or): lhs elements are prefered, so should not
  replace with rhs elements.
* test/ruby/test_array.rb (test_OR_in_order): import the test failed
  by r43969 from rubyspec/core/array/union_spec.rb.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 12:53:31 +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 2b07df37d1 * array.c (rb_ary_uniq_bang): remove duplicate code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 05:13:19 +00:00
glass 95f983f6d0 * array.c (ary_add_hash): set and return values because string keys
will be frozen. [ruby-core:58809] [Bug #9202]

* array.c (rb_ary_uniq_bang): ditto.

* array.c (rb_ary_or): ditto.

* array.c (rb_ary_uniq): ditto.

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

The patch is from normalperson (Eric Wong).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 04:55:51 +00:00
nobu 7566c49068 ruby/ruby.h: RB_BLOCK_CALL_FUNC_ARGLIST
* include/ruby/ruby.h (RB_BLOCK_CALL_FUNC_ARGLIST): for declaration
  argument list of rb_block_call_func.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 07:59:14 +00:00
nobu 32145ebfd6 array.c, enum.c, range.c: rb_block_call_func compatible
* array.c (take_i), range.c (first_i): make rb_block_call_func
  compatible.

* enum.c (collect_all, DEFINE_ENUMFUNCS): add blockarg.

* enum.c ({min,max,minmax,chunk,slicebefore}_ii): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 07:45:00 +00:00
nobu 9f45081627 ruby/ruby.h: add blockarg to rb_block_call_func
* include/ruby/ruby.h (rb_block_call_func): add blockarg.  block
  function can take block argument, e.g., proc {|&blockarg| ...}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 02:26:48 +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
ko1 2bfd722d80 * internal.h: do not use ruby_sized_xrealloc() and ruby_sized_xfree()
if HAVE_MALLOC_USABLE_SIZE (or _WIN32) is defined.
  We don't need these function if malloc_usable_size() is available.
* gc.c: catch up this change.
* gc.c: define HAVE_MALLOC_USABLE_SIZE on _WIN32.
* array.c (ary_resize_capa): do not use ruby_sized_xfree() with
  local variable to avoid "unused local variable" warning.
  This change only has few impact.
* string.c (rb_str_resize): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-25 01:13:31 +00:00
zzak 6720c0aeeb * array.c: [DOC] Add note about negative indices in Array overview
By @ckaenzig [Fixes GH-427] https://github.com/ruby/ruby/pull/427


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-07 17:15:49 +00:00
glass c2f3e600d0 * array.c (rb_ary_shuffle_bang): use RARRAY_PTR_USE() without WB
because there are not new relations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-07 02:08:36 +00:00
glass cf0838f414 * array.c (rb_ary_sample): use rb_ary_dup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-07 01:37:34 +00:00
glass 564a14e497 * array.c (rb_ary_shift_m): use RARRAY_PTR_USE() without WB because
there are not new relations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-06 12:20:39 +00:00
glass 27f2c267fd * array.c (rb_ary_reverse): use RARRAY_PTR_USE().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-06 12:09:31 +00:00
glass da10c47e49 * array.c (rb_ary_sample): use RARRAY_AREF() and RARRAY_PTR_USE()
instead of RARRAY_PTR().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-06 02:50:28 +00:00
glass e90e8b2ef6 * array.c (rb_ary_and): defer hash creation and some refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-06 01:39:55 +00:00
glass adcab6c1bb * array.c (rb_ary_uniq_bang): use rb_ary_modify_check() instead of
rb_ary_modify() because the array will be unshared soon.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-30 03:11:41 +00:00
glass 887ff70f23 * array.c (rb_ary_zip): some refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 14:08:48 +00:00