summaryrefslogtreecommitdiff
path: root/enum.c
AgeCommit message (Collapse)Author
2024-02-12Replace assert with RUBY_ASSERT in enum.cPeter Zhu
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.
2023-09-27[DOC] Missing comment markersNobuyoshi Nakada
2023-08-15[DOC] Improve doc guide compliance (#8221)Burdette Lamar
2023-07-30[DOC] Fix missing word in a commentJoshua Young
2023-06-01[DOC] Mention the edge case of `any?`/`all?`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7883
2023-05-26[DOC] Link fix (#7862)Burdette Lamar
Notes: Merged-By: peterzhu2118 <peter@peterzhu.ca>
2023-05-20[Feature #19643] Direct primitive compare sort for `Array#sort_by`nekoyama32767
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. Notes: Merged: https://github.com/ruby/ruby/pull/7805 Merged-By: nobu <nobu@ruby-lang.org>
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-19[DOC] Return *args to Enumerable method definitionszverok
Notes: Merged: https://github.com/ruby/ruby/pull/7316
2022-12-06Introduce BOP_CMP for optimized comparisonDaniel Colson
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-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-10-19[DOC] Fix typo in Enumerable#slice_beforeKouhei Yanagita
Notes: Merged: https://github.com/ruby/ruby/pull/6577
2022-08-08[DOC] Fix formatting issue in EnumerablePeter Zhu
2022-07-26Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu
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. Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-05-28Revert flawed doc for slice_after, slice_when, and chunk_while (#5952)Burdette Lamar
Restores doc for the methods that were cited in https://bugs.ruby-lang.org/issues/18765. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-04-25Simplify example code for Enumerable#each_with_objectColin Hart
Notes: Merged: https://github.com/ruby/ruby/pull/5825 Merged-By: jeremyevans <code@jeremyevans.net>
2022-03-25[DOC] Repair format and links in What's Here sections (#5711)Burdette Lamar
* Repair format and links in What's Here for Comparable and Array * Repair format for What's Here in enum.c Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-03-23Raise ArgumentError when calling Enumberable#inject without block or argumentsJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/5690
2022-02-07[DOC] Use RDoc link style for links in the same class/modulePeter Zhu
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 Notes: Merged: https://github.com/ruby/ruby/pull/5530
2022-01-08Prefer the dedecated conversion functionNobuyoshi Nakada
2022-01-04Enhanced RDoc for Enumerable (#5393)Burdette Lamar
A little more about the classes that include or extend Enumerable. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-16Make Enumerable#each_cons return object if over sizeJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/5129
2021-11-05Delegate keywords from Enumerable#to_a to #eachJeremy Evans
Fixes [Bug #18289] Notes: Merged: https://github.com/ruby/ruby/pull/5086
2021-10-25Fix `Enumerable#each_cons` and `Enumerable#each_slice` to return a receiverTSUYUSATO Kitsune
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com> Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/1509 Merged-By: nobu <nobu@ruby-lang.org>
2021-10-25[DOC] Fix code markup [ci skip]Nobuyoshi Nakada
Code markup in RDoc must not be concatenated with anothr word.
2021-10-06Accommondate earlier reviews of RDoc for Enumerable (#4943)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-06Enhanced RDoc for Enumerable (#4941)Burdette Lamar
Treated: #sum #uniq #compact Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-05Enhanced RDoc for Enumerable (#4938)Burdette Lamar
Treats: #slice_after #slice_when #chunk_while Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-05Enhanced RDoc for Enumerable#slice_before (#4932)Burdette Lamar
* Enhanced RDoc for Enumerable#slice_before * Enhanced RDoc for Enumerable#slice_before Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-04Enhanced RDoc for Enumerable#chunk (#4930)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-03Using NIL_P macro instead of `== Qnil`S.H
Notes: Merged: https://github.com/ruby/ruby/pull/4925 Merged-By: nobu <nobu@ruby-lang.org>
2021-10-01Enhanced RDoc for Enumerable (#4922)Burdette Lamar
Treated: #drop #drop_while #cycle Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-01Enhanced RDoc for Enumerable (#4918)Burdette Lamar
Treats: #zip #take #take_while Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-30Enhanced RDoc for Enumerable (#4917)Burdette Lamar
Treats: #each_with_index #reverse_each #each_entry #each_slice #each_cons #each_with_object Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-29Enhanced RDoc for Enumerable (#4910)Burdette Lamar
Treats: #min #max #minmax #min_by #max_by #minmax_by #include? Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-28Enhanced RDoc for Enumerable (#4908)Burdette Lamar
Treated: #none? #one? #min Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-28Enhanced RDoc for Enumerable (#4906)Burdette Lamar
Treats: #partition #group_by #tally #first #sort #sort_by #all? #any? Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-20Enhanced RDoc for Enumerable#inject (#4876)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-11Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4805
2021-09-10Enhanced RDoc for Enumerable (#4808)Burdette Lamar
#to_a #to_h #inject Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-07-27Extracted repeatedly defined IDsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4684
2021-05-10Enhanced RDoc for Enumerable (#4479)Burdette Lamar
Methods treated: #count #find #find_index #select #filter_map #reject #map #flat_map Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-05-08Enhanced RDoc for Enumerable (#4473)Burdette Lamar
Enhanced RDoc for Enumerable: #grep and #grep_v. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-03-27Fix Enumerable#tally with some arguments pattern [Feature #17744]Kenichi Kamiya
* 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 Notes: Merged: https://github.com/ruby/ruby/pull/4327 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-26Enumerable#tally with the resulting hash [Feature #17744]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4318 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-20Add write-barrier in tallyNobuyoshi Nakada
2021-03-19Fix Enumerable#inject with high negative fixnums [Bug #17731]Marc-Andre Lafortune
Notes: Merged: https://github.com/ruby/ruby/pull/4288
2021-03-16Improve Enumerable#tally performanceNobuyoshi Nakada
Iteration per second (i/s) | |compare-ruby|built-ruby| |:------|-----------:|---------:| |tally | 52.814| 114.936| | | -| 2.18x| Notes: Merged: https://github.com/ruby/ruby/pull/4278
2021-01-04RDoc: Enhanced introduction for Enumerable (#4004)Burdette Lamar
* RDoc: Enhanced introduction for Enumerable * RDoc: Enhanced introduction for Enumerable * RDoc: Enhanced introduction for Enumerable Notes: Merged-By: marcandre <github@marc-andre.ca>