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

483 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 9143d21b1b
Enumerable#tally with the resulting hash [Feature #17744] 2021-03-26 16:29:21 +09:00
Nobuyoshi Nakada cfadbf2fc4
Add write-barrier in tally 2021-03-20 23:53:57 +09:00
Marc-Andre Lafortune a85ed626f1 Fix Enumerable#inject with high negative fixnums [Bug #17731] 2021-03-19 00:21:41 -04:00
Nobuyoshi Nakada 382d3a4516
Improve Enumerable#tally performance
Iteration per second (i/s)

|       |compare-ruby|built-ruby|
|:------|-----------:|---------:|
|tally  |      52.814|   114.936|
|       |           -|     2.18x|
2021-03-16 23:06:41 +09:00
Burdette Lamar f2d0d4cb0a
RDoc: Enhanced introduction for Enumerable (#4004)
* RDoc: Enhanced introduction for Enumerable

* RDoc: Enhanced introduction for Enumerable

* RDoc: Enhanced introduction for Enumerable
2021-01-04 23:39:13 -05:00
Kazuhiro NISHIYAMA 3fee9e7021
Fix indent [ci skip]
Suggested by @hanachin at
https://github.com/rurema/doctree/pull/2425#discussion_r551327592
2021-01-05 00:19:48 +09:00
zverok b8d33df1d9 Add Enumerable#compact and Enumerator::Lazy#compact 2021-01-02 17:27:24 +09:00
Nobuyoshi Nakada b30d7fea56
Removed leading spaces [ci skip] 2020-12-16 12:14:30 +09:00
Marc-Andre Lafortune d5f0d338c7 Optimize `Enumerable#grep{_v}`
[Bug #17030]
2020-12-15 12:54:45 -05:00
Nobuyoshi Nakada b958e2add8 Removed canonicalization for mathn 2020-11-10 11:14:15 +09:00
S-H-GAMELINKS 8b3653b484 Fix links 2020-11-10 11:04:00 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Nobuyoshi Nakada 3ead2770a1
Respect visibility in non-array Enumerable#inject [Bug #13592] 2020-07-24 21:08:50 +09:00
卜部昌平 c47b805d8c add spaces [ci skip] 2020-06-29 11:05:41 +09:00
卜部昌平 d060ebf83c sum_iter: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Jeremy Evans b212c7c7d1 Update example code in Enumerator#chunk documentation [ci skip]
The code assumed that /usr/share/dict/words did not use mixed
case, and it does at least on a few operating systems.

From CryptoRAT (Luke Elliot)

Fixes [Bug #16957]
2020-06-12 09:11:43 -07:00
szTheory fa37a220f6 docs: fix typo 2020-06-07 10:32:33 +09:00
Masataka Pocke Kuwabara a3f498e44c
Fix max, min, minmax documentation (#3131)
They only need that all objects implement <=>,
but the documentation said it needs Comparable.
2020-05-26 23:48:46 -07:00
Nobuyoshi Nakada 5d430c1b34
Added more NORETURN declarations 2020-05-11 00:40:14 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Marcus Stollsteimer bb05cdcd78 [DOC] Improve documentation for Enumerable#tally 2019-12-22 22:36:14 +01:00
Eli Sadoff 7e9b1609da Added documentation for integer range sums (#1593) 2019-12-11 11:25:54 +09:00
Corey Farwell 69aa927a40 Indicate `find_all` and `select` methods are aliases.
This matches the documentation for `Enumerable::inject` and `Enumerable::reduce` which are also aliases.
2019-12-11 11:15:12 +09:00
Koichi Sasada 36da0b3da1 check interrupts at each frame pop timing.
Asynchronous events such as signal trap, finalization timing,
thread switching and so on are managed by "interrupt_flag".
Ruby's threads check this flag periodically and if a thread
does not check this flag, above events doesn't happen.

This checking is CHECK_INTS() (related) macro and it is placed
at some places (laeve instruction and so on). However, at the end
of C methods, C blocks (IMEMO_IFUNC) etc there are no checking
and it can introduce uninterruptible thread.

To modify this situation, we decide to place CHECK_INTS() at
vm_pop_frame(). It increases interrupt checking points.
[Bug #16366]

This patch can introduce unexpected events...
2019-11-29 17:47:02 +09:00
Kazuki Tsujimoto ff41663403
Fix memory corruption in Enumerable#reverse_each [ruby-dev:50867] [Bug #16354] 2019-11-19 15:35:14 -06:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
卜部昌平 5c7c2d9951 rb_rescue / rb_rescue2 now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 7329b3339a #define RB_BLOCK_CALL_FUNC_STRICT 1
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  Let's start from making
rb_block_call_func_t strict, and apply RB_BLOCK_CALL_FUNC_ARGLIST liberally.
2019-08-27 15:52:26 +09:00
Jeremy Evans e496e96547 Document that Enumerable#sum may not respect redefinition of Range#each
It already documented that it may not respect redefinition
of Integer#+.

Fixes [Bug #13700]
2019-08-25 12:50:19 -07:00
OKURA Masafumi efd37f8fc3 Remove redundant each from `sum` example (#2190) [ci skip]
It used to be `Enumerator#sum`, now it's range of string which calls
`Enumerable#sum` and causes TypeError.
2019-08-17 08:52:23 +09:00
Yusuke Endoh 58dec9625c enum.c: Remove unused #include
transient_heap.h is no longer needed.
2019-08-07 22:24:20 +09:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
Kazuhiro NISHIYAMA 515e106fb7
[DOC] Add link to Enumerable#grep from Enumerable#select 2019-07-09 13:01:11 +09:00
Kazuhiro NISHIYAMA 69509df2f4
squeeze space [ci skip] 2019-06-13 16:42:31 +09:00
Martin Dürst 7f79a86d8b add comments to mention sort.reverse!
For array.c (Array#sort) and enum.c (Enumerable#sort_by),
add comments mentioning that sort.reverse! / sort_by { ... }.reverse!
can/should be used to reverse the result. [ci skip]
2019-06-13 15:30:03 +09:00
Jeremy Evans 17af8bfce6 Make size on an infinite each_slice enumerator return Infinity
Fixes [Bug #15889]
2019-06-02 20:00:35 -07:00
Yusuke Endoh c04ef141d2 enum.c (enum_tally): better example in rdoc 2019-05-23 23:35:26 +09:00
Alfonso Jiménez 0acbdd1ed0
Adding Enumerable#filter_map
[Feature #15323]
Closes: https://github.com/ruby/ruby/pull/2017
2019-05-23 14:39:16 +09:00
Marcus Stollsteimer f782e5bdcf [DOC] Use '&&' instead of 'and' in boolean expression 2019-05-18 13:05:26 +02:00
okuramasafumi 559cad9f2d Improve doc for Enumerable#include? and member?
Existing doc for Enumerable#include? and member? has some problems.
* `IO.constants` is not commonly used, and only some know
    that `SEEK_SET` is actually included in constants.
* `IO.constants` is actually an Array, not the example is not
    appropriate for `Enumerable` module.
So in this commit, the old example is replaced with new one.
New example uses integer range, which is much simpler and easier to
understand.

Closes: https://github.com/ruby/ruby/pull/2168
2019-05-13 00:43:05 +09:00
Urabe, Shyouhei 40b5f2b85d memo.c might not always be initialized
memo.float_value might change inside of hash_sum.  In case it
flipped from false to true there, and the calculated sum is Inf,
memo.c might not be initialized at all.  This is bad.

Found using memory sanitizer:

==55293==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55dfb8d6c529 in rb_float_new_inline internal.h:1814:53
    #1 0x55dfb8d1b30c in enum_sum enum.c:4017:18
    #2 0x55dfb86d75ad in call_cfunc_m1 vm_insnhelper.c:2041:12
    #3 0x55dfb864b141 in vm_call_cfunc_with_frame vm_insnhelper.c:2207:11
    #4 0x55dfb85e843d in vm_call_cfunc vm_insnhelper.c:2225:12
    #5 0x55dfb85e08f3 in vm_call_method_each_type vm_insnhelper.c:2560:9
    #6 0x55dfb85de9c7 in vm_call_method vm_insnhelper.c:2686:13
    #7 0x55dfb849eac6 in vm_call_general vm_insnhelper.c:2730:12
    #8 0x55dfb8686103 in vm_sendish vm_insnhelper.c:3623:11
    #9 0x55dfb84dc29e in vm_exec_core insns.def:789:11
2019-04-26 15:59:40 +09:00
nagachika 39b04bc698 [DOC] Add `ifnone` example to `find` documentation [ci skip]
[Fix GH-2110]

From: OKURA Masafumi <masafumi.o1988@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-12 14:32:31 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
nobu 5133bfad5d enum.c: [DOC] tally does not take a block
[Feature #11076]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-08 09:57:23 +00:00
svn 7199685dc6 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07 08:14:12 +00:00
nobu 673dc51c25 enum.c: Enumerable#tally
* enum.c (enum_tally): new methods Enumerable#tally, which group
  and count elements of the collection.  [Feature #11076]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07 08:14:10 +00:00
nobu e0f1b514d2 enum.c: hosited out enum_hashify
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07 08:14:09 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
Especially over checking argc then calling rb_scan_args just to
raise an ArgumentError.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 07:49:24 +00:00
nobu e7fad40cf2 Build error method name at failure
So `struct nmin_data` size is reduced.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:11:32 +00:00
nobu 36f05c80b6 Adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:11:31 +00:00
nobu 09ef29a78f Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:09:44 +00:00
ko1 5e11de6585 make `RARRAY_PTR_USE` more conservertive.
* 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-12-03 12:36:39 +00:00
ko1 312b105d0e introduce TransientHeap. [Bug #14858]
* transient_heap.c, transient_heap.h: implement TransientHeap (theap).
  theap is designed for Ruby's object system. theap is like Eden heap
  on generational GC terminology. theap allocation is very fast because
  it only needs to bump up pointer and deallocation is also fast because
  we don't do anything. However we need to evacuate (Copy GC terminology)
  if theap memory is long-lived. Evacuation logic is needed for each type.

  See [Bug #14858] for details.

* array.c: Now, theap for T_ARRAY is supported.

  ary_heap_alloc() tries to allocate memory area from theap. If this trial
  sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on.
  We don't need to free theap ptr.

* ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that
  if ary is allocated at theap, force evacuation to malloc'ed memory.
  It makes programs slow, but very compatible with current code because
  theap memory can be evacuated (theap memory will be recycled).

  If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT()
  instead of RARRAY_CONST_PTR(). If you can't understand when evacuation
  will occur, use RARRAY_CONST_PTR().

(re-commit of r65444)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:53:56 +00:00
svn 69b8ffcd5b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:02:12 +00:00
ko1 7d359f9b69 revert r65444 and r65446 because of commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:01:55 +00:00
ko1 90ac549fa6 introduce TransientHeap. [Bug #14858]
* transient_heap.c, transient_heap.h: implement TransientHeap (theap).
  theap is designed for Ruby's object system. theap is like Eden heap
  on generational GC terminology. theap allocation is very fast because
  it only needs to bump up pointer and deallocation is also fast because
  we don't do anything. However we need to evacuate (Copy GC terminology)
  if theap memory is long-lived. Evacuation logic is needed for each type.

  See [Bug #14858] for details.

* array.c: Now, theap for T_ARRAY is supported.

  ary_heap_alloc() tries to allocate memory area from theap. If this trial
  sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on.
  We don't need to free theap ptr.

* ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that
  if ary is allocated at theap, force evacuation to malloc'ed memory.
  It makes programs slow, but very compatible with current code because
  theap memory can be evacuated (theap memory will be recycled).

  If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT()
  instead of RARRAY_CONST_PTR(). If you can't understand when evacuation
  will occur, use RARRAY_CONST_PTR().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 20:46:24 +00:00
ko1 d3edfdc7d9 use RARRAY_AREF() instead of RARRAY_CONST_PTR().
* class.c (rb_keyword_error_new): use RARRAY_AREF() because
  RARRAY_CONST_PTR() can introduce additional overhead in a futre.
  Same fixes for other files.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29 18:00:02 +00:00
ko1 4ed087b0db revisit `RARRAY_PTR()`.
* array.c (yield_indexed_values): use RARRAY_AREF/ASET instead of
  using RARRAY_PTR().

* enum.c (nmin_filter): ditto.

* proc.c (rb_sym_to_proc): ditto.

* enum.c (rb_nmin_run): use RARRAY_PTR_USE() instead of RARRAY_PTR().
  It is safe because they don't make new referecen from an array.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-10 04:17:01 +00:00
kazu 0744b375b8 Fix a typo [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21 08:34:25 +00:00
nobu abe75149d1 Enumerable#to_h with block and so on
[Feature #15143]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20 15:06:56 +00:00
nobu 384fda18b8 warn unused blocks with Enumerable#all? any? one? none?
[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-09-13 11:10:24 +00:00
nobu 97e05dad7f UNREACHABLE_RETURN
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end
  of non-void functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24 05:38:07 +00:00
nobu 67cacdb836 fix sum on infinity
* array.c (rb_ary_sum): consider non-finite floats.
  [ruby-core:88024] [Bug #14926]

* enum.c (sum_iter): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-22 10:47:33 +00:00
nobu 7495b2d2d6 enum.c: bignum counter
* enum.c (imemo_count_up, imemo_count_value): promote the counter
  value to a bignum on overflow.  [Bug #14805]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-02 07:50:18 +00:00
nobu 6bb70c11b3 enum.c: mitigate overflows
* enum.c (enum_count): convert counters to Integer as unsigned
  long, instead of long, to mitigate overflows.
  [ruby-core:87348] [Bug #14805]

* enum.c (ary_inject_op): ditto.

* enum.c (each_with_index_i): ditto, instead of int.

* enum.c (find_index_i, find_index_iter_i): ditto, instead of
  unsigned int.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-02 02:39:34 +00:00
naruse 9b6175b282 memo->u3.cnt is long not int [Bug #14805]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-02 00:51:43 +00:00
eregon b1a8c64483 Add a new #filter alias for #select
* In Enumerable, Enumerator::Lazy, Array, Hash and Set
  [Feature #13784] [ruby-core:82285]
* Share specs for the various #select#select! methods and
  reuse them for #filter/#filter!.
* Add corresponding filter tests for select tests.
* Update NEWS.

[Fix GH-1824]

From: Alexander Patrick <adp90@case.edu>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25 13:52:07 +00:00
nobu 6593c3af8d Fixing some minimal formating on enum.c examples
This will fix the formatting shown on detect|find and revese_arch
generated by RDoc.

[Fix GH-1816]

From: Espartaco Palma <esparta@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 13:29:57 +00:00
shyouhei 3ca0948f68 INFINITY is float. That of double is HUGE_VAL.
It seems HUGE_VAL is already used. Why not eliminate INTINITY.
NAN is also float. That of double is called nan(). This is also
fixed.

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19 01:45:36 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
stomar b5e0b65e57 enum.c: improve docs for Enumerable#{any?,all?,none?,one?}
* enum.c: [DOC] reword docs for Enumerable#{any?,all?,none?,one?}
  to not mention the receiver (`enum') from call-seq, because it
  does not appear in the call-seq of the rendered HTML docs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14 10:21:56 +00:00
kazu c9154899e1 Add more example of `Enumerable#one?` [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 15:01:13 +00:00
marcandre a9770bac63 Add case equality arity to Enumerable#all?, any?, none? and one?,
and specialized Array#any? and Hash#any?
Based on patch by D.E. Akers [#11286]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-10 22:36:28 +00:00
nobu 4b7f531553 enum.c: check argument first
* enum.c (enum_cycle_size): check an argument before the size of
  the receiver, if it is given.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-05 23:32:50 +00:00
marcandre dcb8a22f26 Fix size on Enumerable#cycle when the size is 0 [Bug #14082].
Patch by Kenichi Kamiya

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-05 22:14:25 +00:00
nobu 47db9cb456 enum.c: make constant argument static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-11 02:44:30 +00:00
nobu 243d188f7c enum.c: optimize for integers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-07 04:15:19 +00:00
nobu 73ed79d8d4 enum.c: prefer rb_funcallv to rb_funcall
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-07 04:08:46 +00:00
nobu c1124ff6b6 enum.c: use predefined IDs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-07 03:45:32 +00:00
nobu 1f67a3900f vm_eval.c: rb_lambda_call
* enum.c (enum_collect): make the block arity same as the given
  block.  [Bug #13391]

* internal.h (vm_ifunc): store arity instead of unused id.

* proc.c (rb_vm_block_min_max_arity): return ifunc arity.

* vm_eval.c (rb_lambda_call): call method with lambda block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-18 08:31:02 +00:00
nobu 9cacc53d4a Fix Enumerable#uniq with non single yield arguments
* enum.c (uniq_func, uniq_iter): need packed value as the unique
  key.  [ruby-core:81734] [Bug #13669] [Fix GH-1658]

Author:    Kenichi Kamiya <kachick1@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-21 02:25:27 +00:00
ko1 ff18933b72 rename functions and clean parameters.
* internal.h (rb_yield_lambda): rename to rb_yield_force_blockarg()
  because this function prohibt lambda arg setup (strict setup).

* vm.c (invoke_iseq_block_from_c): remove splattable argument because
  it is not used.

* vm.c (invoke_block_from_c_splattable): rename to invoke_block_from_c_bh()
  because `splattable` doesn't make sense on current this function.

  Also accept `force_blockarg' parameter instead of `splattable` parameter.
  It is more clear.

* vm.c (invoke_block_from_c_unsplattable): rename to
  invoke_block_from_c_proc() and accept `proc` instead of `block'.
  This function is used only by proc block invocation.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-05 06:15:28 +00:00
nobu e4cc791f87 enum.c: check if reentered
* enum.c (cmpint_reenter_check): extract from nmin_cmp and
  nmin_block_cmp.

* enum.c (nmin_cmp): check if reentered before rb_cmpint.
  [Feature #13437]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-30 13:12:22 +00:00
nobu 7cdb2840df enum.c: rb_check_funcall_default for fallback value
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-30 12:47:58 +00:00
watson1978 cf02692f3e Improve performance of Enumerable#{sort_by,min_by,max_by,minmax_by}
This is totally same approach with r58964.

enum.c (sort_by_cmp): use OPTIMIZED_CMP() to compare the objects instead of
    `<=>' method dispatching for Fixnum/Float/String object.

enum.c (nmin_cmp): ditto.
enum.c (min_by_i): ditto.
enum.c (max_by_i): ditto.
enum.c (minmax_by_i_update): ditto.
enum.c (minmax_by_i): ditto.

    Enumerable#sort_by   -> 51 % up
    Enumerable#min_by(n) -> 34 % up
    Enumerable#min_by    -> 37 % up
    Enumerable#max_by(n) -> 61 % up
    Enumerable#max_by    -> 40 % up
    Enumerable#minmax_by -> 67 % up

    [ruby-core:80689] [Bug #13437] [Fix GH-1584]

### Before
  Enumerable#sort_by      5.692k (± 2.2%) i/s -     28.611k in   5.028861s
Enumerable#min_by(n)      8.496k (± 0.5%) i/s -     43.146k in   5.078394s
   Enumerable#min_by      8.678k (± 0.5%) i/s -     43.911k in   5.060128s
Enumerable#max_by(n)      3.306k (± 3.0%) i/s -     16.562k in   5.014727s
   Enumerable#max_by      8.322k (± 2.8%) i/s -     42.400k in   5.099400s
Enumerable#minmax_by      6.769k (± 2.6%) i/s -     34.100k in   5.041354s

### After
  Enumerable#sort_by      8.591k (± 3.0%) i/s -     43.316k in   5.046836s
Enumerable#min_by(n)     11.489k (± 1.2%) i/s -     57.732k in   5.025504s
   Enumerable#min_by     11.835k (± 2.7%) i/s -     60.150k in   5.086450s
Enumerable#max_by(n)      5.322k (± 1.1%) i/s -     26.650k in   5.008289s
   Enumerable#max_by     11.705k (± 0.6%) i/s -     59.262k in   5.062997s
Enumerable#minmax_by     11.323k (± 1.3%) i/s -     57.018k in   5.036565s

### Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  enum = (1..1000).to_a.to_enum

  x.report "Enumerable#sort_by" do
    enum.sort_by { |a| a }
  end

  x.report "Enumerable#min_by(n)" do
    enum.min_by(2) { |a| a }
  end

  x.report "Enumerable#min_by" do
    enum.min_by { |a| a }
  end

  x.report "Enumerable#max_by(n)" do
    enum.max_by(2) { |a| a }
  end

  x.report "Enumerable#max_by" do
    enum.max_by { |a| a }
  end

  x.report "Enumerable#minmax_by" do
    enum.minmax_by { |a| a }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-30 09:00:56 +00:00
nobu 5e25bfa2fb enum.c: respect method visibility
* enum.c (ary_inject_op): should respect method visibility, do not
  optimize uncallable method.  [ruby-core:81349] [Bug #13592]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-24 08:00:42 +00:00
nobu 976becf7eb vm_args.c: arity check of lambda
* vm_eval.c (rb_yield_lambda): new function which yields an array
  to a proc and splat to a lambda.  mainly for Enumerable only.

* vm_args.c (setup_parameters_complex): remove special lambda
  splatting for [Bug #9605].  [ruby-core:77065] [Bug #12705]

* vm_insnhelper.c (vm_callee_setup_block_arg): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-19 01:11:12 +00:00
stomar b4baeb5af6 documentation for sort methods
* array.c: [DOC] fix grammar in Array#sort, #sort!, #sort_by!,
  move references below the code example, add a missing reference.
* enum.c: [DOC] fix grammar in Enumerable#sort, #sort_by.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-04 13:13:50 +00:00
stomar 453199c4b6 enum.c: documentation for Enumerable#sort_by
* enum.c: [DOC] improve structure of docs for Enumerable#sort_by,
  adopt explanation of the comparison block from Array#sort_by,
  drop mention of 1.8, fix typos.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-04 13:12:20 +00:00
akr cd5f5715d7 [DOC] Update an obsolete example for slice_before.
The argument for Enumerable#slice_before is is removed at Ruby 2.3.

Reported by Shyouhei Urabe.  [Bug #13202]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-09 14:28:27 +00:00
nobu 70410163f5 enum.c: write barrier
* enum.c (rb_nmin_run): set the class with write barrier.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-27 03:24:45 +00:00
nobu 2c1bdb5849 enum.c (rb_nmin_run): adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-27 03:24:44 +00:00
nobu 559bef4228 Enumerable#{min,min_by,max,max_by} [ci skip]
* enum.c: [DOC] Enumerable#{min,min_by,max,max_by} return a sorted
  array when +n+ argument is used.

* enum.c: Small typo : minimum -> maximum

[Bug #13161]
Author:    Eric Duminil <eric.duminil@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-27 03:24:43 +00:00
kazu a7bc6c1b8f [DOC] Add empty example to enum.all? and any?
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-25 14:28:42 +00:00
mrkn 48f5f5915b array.c, enum.c: change sum algorithm
* array.c (rb_ary_sum): change the algorithm to Kahan-Babuska balancing
  summation to be more precise.
  [Feature #12871] [ruby-core:77771]

* enum.c (sum_iter, enum_sum): ditto.

* test_array.rb, test_enum.rb: add an assertion for the above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 13:40:31 +00:00
nobu 5b3b8554c9 unstable sort [ci skip]
* array.c (rb_ary_sort_bang, rb_ary_sort, rb_ary_sort_by_bang):
  [DOC] describe that sort may not be stable.
* enum.c (enum_sort, enum_sort_by): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-13 02:35:34 +00:00
marcandre ea7a3644d3 * enum.c: [DOC] Improve doc [ci-skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-06 04:35:26 +00:00
hsbt 364a0879c9 * enum.c: Add reduce/inject alias note.
[fix GH-1400][ci skip] Patch by @getaaron

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-06 01:53:17 +00:00
marcandre 69846644d2 * enum.c: Make Enumerable#chunk with no block return
an Enumerator [#2172]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-04 18:25:16 +00:00
nobu 0cc169d1de fid typos [ci skip]
* fix typos, "a" before "Integer" to "an".  [Fix GH-1438]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-24 02:28:25 +00:00