summaryrefslogtreecommitdiff
path: root/enum.c
Commit message (Collapse)AuthorAgeFilesLines
* Introduce BOP_CMP for optimized comparisonDaniel Colson2022-12-061-33/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-30/+30
|
* [DOC] Fix typo in Enumerable#slice_beforeKouhei Yanagita2022-10-191-1/+1
|
* [DOC] Fix formatting issue in EnumerablePeter Zhu2022-08-081-1/+1
|
* Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu2022-07-261-2/+2
| | | | | | 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.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-307/+307
| | | | [Misc #18891]
* Revert flawed doc for slice_after, slice_when, and chunk_while (#5952)Burdette Lamar2022-05-281-55/+107
| | | Restores doc for the methods that were cited in https://bugs.ruby-lang.org/issues/18765.
* Simplify example code for Enumerable#each_with_objectColin Hart2022-04-251-2/+4
|
* [DOC] Repair format and links in What's Here sections (#5711)Burdette Lamar2022-03-251-61/+65
| | | | | * Repair format and links in What's Here for Comparable and Array * Repair format for What's Here in enum.c
* Raise ArgumentError when calling Enumberable#inject without block or argumentsJeremy Evans2022-03-231-1/+9
| | | | | | | | 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]
* [DOC] Use RDoc link style for links in the same class/modulePeter Zhu2022-02-071-6/+6
| | | | | | | | | | 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
* Prefer the dedecated conversion functionNobuyoshi Nakada2022-01-081-1/+1
|
* Enhanced RDoc for Enumerable (#5393)Burdette Lamar2022-01-041-3/+19
| | | A little more about the classes that include or extend Enumerable.
* Make Enumerable#each_cons return object if over sizeJeremy Evans2021-11-161-5/+5
| | | | | | | | | This behavior changed in dfb47bbd17c3c2b8ce17dbafaf62df023b0224b2, 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.
* Delegate keywords from Enumerable#to_a to #eachJeremy Evans2021-11-051-1/+1
| | | | Fixes [Bug #18289]
* Fix `Enumerable#each_cons` and `Enumerable#each_slice` to return a receiverTSUYUSATO Kitsune2021-10-251-6/+6
| | | | Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com> Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
* [DOC] Fix code markup [ci skip]Nobuyoshi Nakada2021-10-251-2/+2
| | | | Code markup in RDoc must not be concatenated with anothr word.
* Accommondate earlier reviews of RDoc for Enumerable (#4943)Burdette Lamar2021-10-061-8/+36
|
* Enhanced RDoc for Enumerable (#4941)Burdette Lamar2021-10-061-38/+40
| | | | | | | | Treated: #sum #uniq #compact
* Enhanced RDoc for Enumerable (#4938)Burdette Lamar2021-10-051-110/+57
| | | | | | | | Treats: #slice_after #slice_when #chunk_while
* Enhanced RDoc for Enumerable#slice_before (#4932)Burdette Lamar2021-10-051-17/+33
| | | | | * Enhanced RDoc for Enumerable#slice_before * Enhanced RDoc for Enumerable#slice_before
* Enhanced RDoc for Enumerable#chunk (#4930)Burdette Lamar2021-10-041-45/+62
|
* Using NIL_P macro instead of `== Qnil`S.H2021-10-031-2/+2
|
* Enhanced RDoc for Enumerable (#4922)Burdette Lamar2021-10-011-29/+46
| | | | | | | | Treated: #drop #drop_while #cycle
* Enhanced RDoc for Enumerable (#4918)Burdette Lamar2021-10-011-35/+80
| | | | | | | | Treats: #zip #take #take_while
* Enhanced RDoc for Enumerable (#4917)Burdette Lamar2021-09-301-75/+110
| | | | | | | | | | | Treats: #each_with_index #reverse_each #each_entry #each_slice #each_cons #each_with_object
* Enhanced RDoc for Enumerable (#4910)Burdette Lamar2021-09-291-124/+160
| | | | | | | | | | | | Treats: #min #max #minmax #min_by #max_by #minmax_by #include?
* Enhanced RDoc for Enumerable (#4908)Burdette Lamar2021-09-281-58/+121
| | | | | | | | Treated: #none? #one? #min
* Enhanced RDoc for Enumerable (#4906)Burdette Lamar2021-09-281-88/+176
| | | | | | | | | | | | | Treats: #partition #group_by #tally #first #sort #sort_by #all? #any?
* Enhanced RDoc for Enumerable#inject (#4876)Burdette Lamar2021-09-201-38/+131
|
* Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS2021-09-111-3/+3
|
* Enhanced RDoc for Enumerable (#4808)Burdette Lamar2021-09-101-26/+21
| | | | | | #to_a #to_h #inject
* Extracted repeatedly defined IDsNobuyoshi Nakada2021-07-271-27/+53
|
* Enhanced RDoc for Enumerable (#4479)Burdette Lamar2021-05-101-101/+104
| | | | | | | | | | | | | Methods treated: #count #find #find_index #select #filter_map #reject #map #flat_map
* Enhanced RDoc for Enumerable (#4473)Burdette Lamar2021-05-081-21/+39
| | | Enhanced RDoc for Enumerable: #grep and #grep_v.
* Fix Enumerable#tally with some arguments pattern [Feature #17744]Kenichi Kamiya2021-03-271-3/+7
| | | | | | | | | | | | | | * 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
* Enumerable#tally with the resulting hash [Feature #17744]Nobuyoshi Nakada2021-03-261-6/+22
|
* Add write-barrier in tallyNobuyoshi Nakada2021-03-201-1/+4
|
* Fix Enumerable#inject with high negative fixnums [Bug #17731]Marc-Andre Lafortune2021-03-191-1/+1
|
* Improve Enumerable#tally performanceNobuyoshi Nakada2021-03-161-6/+14
| | | | | | | | | Iteration per second (i/s) | |compare-ruby|built-ruby| |:------|-----------:|---------:| |tally | 52.814| 114.936| | | -| 2.18x|
* RDoc: Enhanced introduction for Enumerable (#4004)Burdette Lamar2021-01-041-7/+129
| | | | | | | * RDoc: Enhanced introduction for Enumerable * RDoc: Enhanced introduction for Enumerable * RDoc: Enhanced introduction for Enumerable
* Fix indent [ci skip]Kazuhiro NISHIYAMA2021-01-051-4/+4
| | | | | Suggested by @hanachin at https://github.com/rurema/doctree/pull/2425#discussion_r551327592
* Add Enumerable#compact and Enumerator::Lazy#compactzverok2021-01-021-0/+43
|
* Removed leading spaces [ci skip]Nobuyoshi Nakada2020-12-161-1/+1
|
* Optimize `Enumerable#grep{_v}`Marc-Andre Lafortune2020-12-151-12/+40
| | | | [Bug #17030]
* Removed canonicalization for mathnNobuyoshi Nakada2020-11-101-10/+1
|
* Fix linksS-H-GAMELINKS2020-11-101-1/+1
|
* Don't redefine #rb_intern over and over againStefan Stüben2020-10-211-4/+1
|
* Respect visibility in non-array Enumerable#inject [Bug #13592]Nobuyoshi Nakada2020-07-241-1/+1
|
* add spaces [ci skip]卜部昌平2020-06-291-0/+14
|