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

478 Коммитов

Автор SHA1 Сообщение Дата
Peter Zhu 436191abe0 Replace assert with RUBY_ASSERT in enum.c
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
2024-02-12 15:07:47 -05:00
Nobuyoshi Nakada 50520cc193
[DOC] Missing comment markers 2023-09-27 16:18:05 +09:00
Burdette Lamar 8c5b9ebf71
[DOC] Improve doc guide compliance (#8221) 2023-08-15 14:43:58 -04:00
Joshua Young 4bdb61b665
[DOC] Fix missing word in a comment 2023-07-30 01:02:20 +09:00
Nobuyoshi Nakada a5e1d549b5 [DOC] Mention the edge case of `any?`/`all?` 2023-06-01 21:44:53 +09:00
Burdette Lamar d62ae18797
[DOC] Link fix (#7862) 2023-05-26 09:20:18 -04:00
nekoyama32767 87217f26f1
[Feature #19643] Direct primitive compare sort for `Array#sort_by`
In most of case `sort_by` works on primitive type.
Using `qsort_r` with function pointer is much slower than compare data directly.

I implement an intro sort which compare primitive data directly for `sort_by`.
We can even afford an O(n) type check before primitive data sort.
It still go faster.
2023-05-20 19:40:27 +09:00
BurdetteLamar 3b239d2480 Remove (newly unneeded) remarks about aliases 2023-02-19 14:26:34 -08:00
zverok 976cc3852b [DOC] Return *args to Enumerable method definitions 2023-02-19 22:32:52 +02:00
Daniel Colson e69b91fae4 Introduce BOP_CMP for optimized comparison
Prior to this commit the `OPTIMIZED_CMP` macro relied on a method lookup
to determine whether `<=>` was overridden. The result of the lookup was
cached, but only for the duration of the specific method that
initialized the cmp_opt_data cache structure.

With this method lookup, `[x,y].max` is slower than doing `x > y ?
x : y` even though there's an optimized instruction for "new array max".
(John noticed somebody a proposed micro-optimization based on this fact
in https://github.com/mastodon/mastodon/pull/19903.)

```rb
a, b = 1, 2
Benchmark.ips do |bm|
  bm.report('conditional') { a > b ? a : b }
  bm.report('method') { [a, b].max }
  bm.compare!
end
```

Before:

```
Comparison:
         conditional: 22603733.2 i/s
              method: 19820412.7 i/s - 1.14x  (± 0.00) slower
```

This commit replaces the method lookup with a new CMP basic op, which
gives the examples above equivalent performance.

After:

```
Comparison:
              method: 24022466.5 i/s
         conditional: 23851094.2 i/s - same-ish: difference falls within
error
```

Relevant benchmarks show an improvement to Array#max and Array#min when
not using the optimized newarray_max instruction as well. They are
noticeably faster for small arrays with the relevant types, and the same
or maybe a touch faster on larger arrays.

```
$ make benchmark COMPARE_RUBY=<master@5958c305> ITEM=array_min
$ make benchmark COMPARE_RUBY=<master@5958c305> ITEM=array_max
```

The benchmarks added in this commit also look generally improved.

Co-authored-by: John Hawthorn <jhawthorn@github.com>
2022-12-06 12:37:23 -08:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Kouhei Yanagita f982a26374 [DOC] Fix typo in Enumerable#slice_before 2022-10-19 09:14:50 +09:00
Peter Zhu a24c607e30 [DOC] Fix formatting issue in Enumerable 2022-08-08 09:26:07 -04:00
Peter Zhu efb91ff19b Rename rb_ary_tmp_new to rb_ary_hidden_new
rb_ary_tmp_new suggests that the array is temporary in some way, but
that's not true, it just creates an array that's hidden and not on the
transient heap. This commit renames it to rb_ary_hidden_new.
2022-07-26 09:12:09 -04:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Burdette Lamar 8038d5e40a
Revert flawed doc for slice_after, slice_when, and chunk_while (#5952)
Restores doc for the methods that were cited in https://bugs.ruby-lang.org/issues/18765.
2022-05-28 14:20:00 -05:00
Colin Hart 9e8841e592
Simplify example code for Enumerable#each_with_object 2022-04-25 12:32:29 -07:00
Burdette Lamar f918f6e4e7
[DOC] Repair format and links in What's Here sections (#5711)
* Repair format and links in What's Here for Comparable and Array

* Repair format for What's Here in enum.c
2022-03-25 10:52:06 -05:00
Jeremy Evans 8f1c69f27c Raise ArgumentError when calling Enumberable#inject without block or arguments
Previously, this would work as expected if the enumerable contained
0 or 1 element, and would raise LocalJumpError otherwise. That
inconsistent behavior is likely to lead to bugs.

Fixes [Bug #18635]
2022-03-23 07:55:49 -07:00
Peter Zhu a32e5e1b97 [DOC] Use RDoc link style for links in the same class/module
I used this regex:

(?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Nobuyoshi Nakada 32a0d9dd4b
Prefer the dedecated conversion function 2022-01-08 12:49:39 +09:00
Burdette Lamar 6326112e16
Enhanced RDoc for Enumerable (#5393)
A little more about the classes that include or extend Enumerable.
2022-01-04 18:39:07 -06:00
Jeremy Evans a5cff7cc5d Make Enumerable#each_cons return object if over size
This behavior changed in dfb47bbd17,
but only for normal exit, not for early exit.  Fix it for early
exit as well.

While here, fix example code in documentation so that it doesn't
indicate that the method returns nil.
2021-11-16 19:31:35 -08:00
Jeremy Evans e83c02a768 Delegate keywords from Enumerable#to_a to #each
Fixes [Bug #18289]
2021-11-05 06:22:14 -09:00
TSUYUSATO Kitsune dfb47bbd17
Fix `Enumerable#each_cons` and `Enumerable#each_slice` to return a receiver
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2021-10-25 12:13:44 +09:00
Nobuyoshi Nakada 4fb71575e2
[DOC] Fix code markup [ci skip]
Code markup in RDoc must not be concatenated with anothr word.
2021-10-25 01:04:51 +09:00
Burdette Lamar 7caeead36f
Accommondate earlier reviews of RDoc for Enumerable (#4943) 2021-10-06 19:06:17 -05:00
Burdette Lamar fb122042e0
Enhanced RDoc for Enumerable (#4941)
Treated:

    #sum
    #uniq
    #compact
2021-10-06 15:51:49 -05:00
Burdette Lamar abd473928e
Enhanced RDoc for Enumerable (#4938)
Treats:

    #slice_after
    #slice_when
    #chunk_while
2021-10-05 18:57:06 -05:00
Burdette Lamar 279b2b5b60
Enhanced RDoc for Enumerable#slice_before (#4932)
* Enhanced RDoc for Enumerable#slice_before

* Enhanced RDoc for Enumerable#slice_before
2021-10-05 10:52:51 -05:00
Burdette Lamar 8dc546b6b6
Enhanced RDoc for Enumerable#chunk (#4930) 2021-10-04 10:41:12 -05:00
S.H dc9112cf10
Using NIL_P macro instead of `== Qnil` 2021-10-03 22:34:45 +09:00
Burdette Lamar 8c10fd2583
Enhanced RDoc for Enumerable (#4922)
Treated:

    #drop
    #drop_while
    #cycle
2021-10-01 17:51:39 -05:00
Burdette Lamar 27d9935d51
Enhanced RDoc for Enumerable (#4918)
Treats:

    #zip
    #take
    #take_while
2021-10-01 13:44:28 -05:00
Burdette Lamar a55a5fc684
Enhanced RDoc for Enumerable (#4917)
Treats:

    #each_with_index
    #reverse_each
    #each_entry
    #each_slice
    #each_cons
    #each_with_object
2021-09-30 15:46:54 -05:00
Burdette Lamar 49edaa061f
Enhanced RDoc for Enumerable (#4910)
Treats:

    #min
    #max
    #minmax
    #min_by
    #max_by
    #minmax_by
    #include?
2021-09-29 18:04:29 -05:00
Burdette Lamar 0182bf615a
Enhanced RDoc for Enumerable (#4908)
Treated:

    #none?
    #one?
    #min
2021-09-28 18:20:58 -05:00
Burdette Lamar 1e10099e09
Enhanced RDoc for Enumerable (#4906)
Treats:

    #partition
    #group_by
    #tally
    #first
    #sort
    #sort_by
    #all?
    #any?
2021-09-28 11:38:35 -05:00
Burdette Lamar 046f1bf492
Enhanced RDoc for Enumerable#inject (#4876) 2021-09-20 18:19:21 -05:00
S-H-GAMELINKS 032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
Burdette Lamar 967b9743fa
Enhanced RDoc for Enumerable (#4808)
#to_a
    #to_h
    #inject
2021-09-10 17:21:21 -05:00
Nobuyoshi Nakada 03e7fc895e Extracted repeatedly defined IDs 2021-07-27 15:40:27 +09:00
Burdette Lamar d2d443efc1
Enhanced RDoc for Enumerable (#4479)
Methods treated:

    #count
    #find
    #find_index
    #select
    #filter_map
    #reject
    #map
    #flat_map
2021-05-10 14:00:36 -05:00
Burdette Lamar 43380401fa
Enhanced RDoc for Enumerable (#4473)
Enhanced RDoc for Enumerable: #grep and #grep_v.
2021-05-08 14:50:15 -05:00
Kenichi Kamiya aceb8c0b4b
Fix Enumerable#tally with some arguments pattern [Feature #17744]
* Add test cases for Enumerable#tally with hash argument

* Add ruby/spec for Enumerable#tally with hash argument

* Fix Enumerable#tally does not update given frozen hash

* Add test cases for Enumerable#tally with hash convertible arguments

* Fix SEGV when Enumerable#tally takes non Hash convertible

* FIx cosmetic damage enum.c
2021-03-27 12:55:46 +09:00
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