summaryrefslogtreecommitdiff
path: root/range.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove (newly unneeded) remarks about aliasesBurdetteLamar2023-02-191-3/+0
|
* [Bug #19426] Fix endless `Range#step` with `#succ` methodNobuyoshi Nakada2023-02-091-1/+5
|
* [DOC] Fix most of Range#cover? marked as verbatimMarco Costa2022-12-231-42/+42
|
* Introduce BOP_CMP for optimized comparisonDaniel Colson2022-12-061-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Raise TypeError for endless non-numeric range include?Jeremy Evans2022-11-241-12/+37
| | | | | | | | | | | | | | | | 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]
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-7/+7
|
* Range#size returns nil for (.."a") and (nil..)Yusuke Endoh2022-10-211-1/+3
| | | | Fixes [Bug #18983]
* rb_int_range_last: properly handle non-exclusive rangeJean Boussier2022-09-041-4/+4
| | | | [Bug #18994]
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-281/+281
| | | | [Misc #18891]
* Fix Range#cover? returning true for beginless ranges of different typesJeremy Evans2022-06-061-1/+53
| | | | | | | | | | | | | 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]
* Document beginless, endless ranges in Range class documentationJeremy Evans2022-04-251-1/+10
|
* Repaired What's Here sections for Range, String, Symbol, Struct (#5735)Burdette Lamar2022-03-301-26/+26
| | | Repaired What's Here sections for Range, String, Symbol, Struct.
* [DOC] Simplify operator method referencesNobuyoshi Nakada2022-02-121-3/+2
|
* Fix Range#include? for beginless exclusive string rangesJeremy Evans2022-02-091-0/+3
| | | | | | | | | 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]
* [DOC] Fix broken links to operator methodsNobuyoshi Nakada2022-02-081-1/+1
| | | | | Once https://github.com/ruby/rdoc/pull/865 is merged, these hacks are no longer needed.
* [DOC] Fix broken links to literals.rdocNobuyoshi Nakada2022-02-081-1/+1
|
* [DOC] Use RDoc link style for links in the same class/modulePeter Zhu2022-02-071-5/+5
| | | | | | | | | | 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
* [DOC] Use RDoc link style for links to other classes/modulesPeter Zhu2022-02-071-2/+2
| | | | | | | | | | 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
* Adding links to literals and Kernel (#5192)Burdette Lamar2021-12-031-8/+10
| | | | * Adding links to literals and Kernel
* Some codes replace to `RBOOL` macro (#5023)S.H2021-11-091-4/+2
| | | | | | | * Some code replace and using RBOOL macro * Fix indent * Using RBOOL in syserr_eqq function
* [DOC] Fix code markup [ci skip]Nobuyoshi Nakada2021-10-251-2/+2
| | | | Code markup in RDoc must not be concatenated with anothr word.
* Unify iteration argumentsNobuyoshi Nakada2021-10-101-14/+2
|
* Update iteration step in step_i_iterNobuyoshi Nakada2021-10-101-10/+6
|
* Refactor sym_step_i functionS.H2021-10-101-9/+11
|
* Using NIL_P macro instead of `== Qnil`S.H2021-10-031-2/+2
|
* Remove unnecessary checks in `Range#each` [Bug #18237]Jörg W Mittag2021-10-031-1/+0
| | | | | | | | | | | | | | | 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.
* Correct two errors in Range RDoc (#4889)Burdette Lamar2021-09-231-2/+2
|
* What's Here for Range (#4881)Burdette Lamar2021-09-221-4/+88
|
* Enhanced RDoc for Range (#4870)Burdette Lamar2021-09-201-88/+151
| | | Introductory material revised.
* Enhanced RDoc for Range (#4847)Burdette Lamar2021-09-181-66/+190
| | | | | | | | | | | Treated: #to_s #inspect #=== #include? #cover? #count
* Enhanced RDoc for Range#minmax (#4846)Burdette Lamar2021-09-151-6/+40
|
* Enhanced RDoc for Range#max (#4844)Burdette Lamar2021-09-151-34/+78
|
* Enhanced RDoc for Range#min (#4842)Burdette Lamar2021-09-151-10/+73
|
* [DOC] Fix broken links [ci skip]Nobuyoshi Nakada2021-09-151-1/+1
| | | | | | * 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.
* Enhanced RDoc for Range (#4839)Burdette Lamar2021-09-141-46/+81
| | | | | | | | | | | | Treated: #size #to_a #each #begin #end #first #last
* Bsearch doc for Array and Range (#4838)Burdette Lamar2021-09-141-44/+2
| | | This PR creates doc/bsearch.rdoc to provide common documentation for bsearch in Array and Range.
* Enhanced RDoc for Range (#4833)Burdette Lamar2021-09-131-55/+94
| | | | | | | | | | | Treated: ::new #include_end? #== #eql? #hash #step
* Using RB_FLOAT_TYPE_P macroS-H-GAMELINKS2021-09-121-1/+1
|
* Using RBOOL macroS.H2021-08-021-8/+3
|
* Refactor sym_each_i functionS-H-GAMELINKS2021-07-221-2/+1
|
* Use public allocators for creating new T_OBJECT objectsAaron Patterson2020-10-281-4/+1
| | | | This way the header flags and object internals are set correctly
* numeric.c, range.c: prohibit zero stepKenta Murata2020-10-231-0/+7
| | | | | | | | | * numeric.c: prohibit zero step in Numeric#step * range.c: prohibit zero step in Range#step * Fix ruby-spec [Feature #15573]
* Don't redefine #rb_intern over and over againStefan Stüben2020-10-211-6/+3
|
* Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)Kenta Murata2020-10-211-18/+51
| | | | | | | | | | | | | | | | | * 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]
* range.c: Fix an exception message in rb_range_beg_lenKenta Murata2020-10-201-5/+2
| | | | [Bug #17271]
* freeze all Range objects.v3_0_0_preview1Koichi Sasada2020-09-251-0/+4
| | | | | Matz want to try to freeze all Range objects. [Feature #15504]
* Removed trailing spaces [ci skip]Nobuyoshi Nakada2020-09-021-1/+1
|
* Update documentation for Range#maxJeremy Evans2020-09-011-8/+28
|
* Revert "Fix Range#{max,minmax} for range with integer beginning and ↵Jeremy Evans2020-09-011-18/+3
| | | | | | non-integer end" This reverts commit 8900a25581822759daca528d46a75e0b743fc22e.
* Revert "Special case Range#max for integer beginning and Float::Infinity end"Jeremy Evans2020-09-011-9/+0
| | | | This reverts commit 05bf811c2839628aaef3d565daedb28be80d47ef.