summaryrefslogtreecommitdiff
path: root/range.c
AgeCommit message (Collapse)Author
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-09[Bug #19426] Fix endless `Range#step` with `#succ` methodNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7277
2022-12-23[DOC] Fix most of Range#cover? marked as verbatimMarco Costa
Notes: Merged: https://github.com/ruby/ruby/pull/7005 Merged-By: nobu <nobu@ruby-lang.org>
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-24Raise TypeError for endless non-numeric range include?Jeremy Evans
Beginless ranges previously raised TypeError for this case, except for string ranges, which had unexpected behavior: ('a'..'z').include?('ww') # false (..'z').include?('ww') # previously true, now TypeError Use of include? with endless ranges could previously result in an infinite loop. This splits off a range_string_cover_internal function from range_include_internal. Fixes [Bug #18580] Notes: Merged: https://github.com/ruby/ruby/pull/6261
2022-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-10-21Range#size returns nil for (.."a") and (nil..)Yusuke Endoh
Fixes [Bug #18983] Notes: Merged: https://github.com/ruby/ruby/pull/6604
2022-09-04rb_int_range_last: properly handle non-exclusive rangeJean Boussier
[Bug #18994] Notes: Merged: https://github.com/ruby/ruby/pull/6324
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-06-06Fix Range#cover? returning true for beginless ranges of different typesJeremy Evans
Previously `(2..).cover?("2"..)` was false, but `(..2).cover?(.."2")` was true. This changes it so both are false, treating beginless ranges the same as endless ranges in regards to type checks. This also adds documentation to #cover? to describe behavior with beginless and endless ranges, testing each documentation example, which is how this bug was found. Fixes [Bug #18155] Notes: Merged: https://github.com/ruby/ruby/pull/5831
2022-04-25Document beginless, endless ranges in Range class documentationJeremy Evans
2022-03-30Repaired What's Here sections for Range, String, Symbol, Struct (#5735)Burdette Lamar
Repaired What's Here sections for Range, String, Symbol, Struct. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-02-12[DOC] Simplify operator method referencesNobuyoshi Nakada
2022-02-09Fix Range#include? for beginless exclusive string rangesJeremy Evans
Previously, include? would return true for the end of the range, when it should return false because the range is exclusive. Research and Analysis by Victor Shepelev. Fixes [Bug #18577] Notes: Merged: https://github.com/ruby/ruby/pull/5541
2022-02-08[DOC] Fix broken links to operator methodsNobuyoshi Nakada
Once https://github.com/ruby/rdoc/pull/865 is merged, these hacks are no longer needed.
2022-02-08[DOC] Fix broken links to literals.rdocNobuyoshi Nakada
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-02-07[DOC] Use RDoc link style for links to other classes/modulesPeter Zhu
I used this regex: ([A-Za-z]+)\.html#(?: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
2021-12-03Adding links to literals and Kernel (#5192)Burdette Lamar
* Adding links to literals and Kernel Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-09Some codes replace to `RBOOL` macro (#5023)S.H
* Some code replace and using RBOOL macro * Fix indent * Using RBOOL in syserr_eqq function Notes: 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-10Unify iteration argumentsNobuyoshi Nakada
2021-10-10Update iteration step in step_i_iterNobuyoshi Nakada
2021-10-10Refactor sym_step_i functionS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4923 Merged-By: nobu <nobu@ruby-lang.org>
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-03Remove unnecessary checks in `Range#each` [Bug #18237]Jörg W Mittag
In commit:7817a438eb1803e7b3358f43bd1f38479badfbdc, the implementation of `Time#succ`, which had been deprecated for 10 years, was finally removed. During that time, there was an explicit `instance_of?` check in source:range.c#L350 with a comment that the check should be removed once `Time#succ` is removed. Since `Time#succ` is now gone, this check should be removed. Note: this should be coordinated with adding a version guard to the corresponding check in ruby/spec as well. Notes: Merged: https://github.com/ruby/ruby/pull/4928 Merged-By: nobu <nobu@ruby-lang.org>
2021-09-23Correct two errors in Range RDoc (#4889)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-22What's Here for Range (#4881)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-20Enhanced RDoc for Range (#4870)Burdette Lamar
Introductory material revised. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-18Enhanced RDoc for Range (#4847)Burdette Lamar
Treated: #to_s #inspect #=== #include? #cover? #count Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-15Enhanced RDoc for Range#minmax (#4846)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-15Enhanced RDoc for Range#max (#4844)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-15Enhanced RDoc for Range#min (#4842)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-15[DOC] Fix broken links [ci skip]Nobuyoshi Nakada
* As the "doc/" prefix is specified by the `--page-dir` option, remove from the rdoc references. * Refer to the original .rdoc instead of the converted .html.
2021-09-14Enhanced RDoc for Range (#4839)Burdette Lamar
Treated: #size #to_a #each #begin #end #first #last Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-14Bsearch doc for Array and Range (#4838)Burdette Lamar
This PR creates doc/bsearch.rdoc to provide common documentation for bsearch in Array and Range. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-13Enhanced RDoc for Range (#4833)Burdette Lamar
Treated: ::new #include_end? #== #eql? #hash #step Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-12Using RB_FLOAT_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4821
2021-08-02Using RBOOL macroS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4695 Merged-By: nobu <nobu@ruby-lang.org>
2021-07-22Refactor sym_each_i functionS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4644
2020-10-28Use public allocators for creating new T_OBJECT objectsAaron Patterson
This way the header flags and object internals are set correctly Notes: Merged: https://github.com/ruby/ruby/pull/3719
2020-10-23numeric.c, range.c: prohibit zero stepKenta Murata
* numeric.c: prohibit zero step in Numeric#step * range.c: prohibit zero step in Range#step * Fix ruby-spec [Feature #15573] Notes: Merged: https://github.com/ruby/ruby/pull/3689 Merged-By: mrkn <mrkn@ruby-lang.org>
2020-10-21Don't redefine #rb_intern over and over againStefan Stüben
Notes: Merged: https://github.com/ruby/ruby/pull/3589
2020-10-21Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)Kenta Murata
* Support ArithmeticSequence in Array#slice * Extract rb_range_component_beg_len * Use rb_range_values to check Range object * Fix ary_make_partial_step * Fix for negative step cases * range.c: Describe the role of err argument in rb_range_component_beg_len * Raise a RangeError when an arithmetic sequence refers the outside of an array [Feature #16812] Notes: Merged-By: mrkn <mrkn@ruby-lang.org>
2020-10-20range.c: Fix an exception message in rb_range_beg_lenKenta Murata
[Bug #17271]
2020-09-25freeze all Range objects.v3_0_0_preview1Koichi Sasada
Matz want to try to freeze all Range objects. [Feature #15504] Notes: Merged: https://github.com/ruby/ruby/pull/3583
2020-09-02Removed trailing spaces [ci skip]Nobuyoshi Nakada
2020-09-01Update documentation for Range#maxJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/3500
2020-09-01Revert "Fix Range#{max,minmax} for range with integer beginning and ↵Jeremy Evans
non-integer end" This reverts commit 8900a25581822759daca528d46a75e0b743fc22e. Notes: Merged: https://github.com/ruby/ruby/pull/3500
2020-09-01Revert "Special case Range#max for integer beginning and Float::Infinity end"Jeremy Evans
This reverts commit 05bf811c2839628aaef3d565daedb28be80d47ef. Notes: Merged: https://github.com/ruby/ruby/pull/3500