summaryrefslogtreecommitdiff
path: root/range.c
AgeCommit message (Collapse)Author
2025-03-21[DOC] beginless and endless ranges inspect returns "nil..nil" alwaysflavio-b
Small correction to the Range docs. All beginless (nil..) and endless (..nil) ranges, as well as fully open ranges (nil..nil), display "nil..nil" when inspected, regardless of their original syntax. Notes: Merged: https://github.com/ruby/ruby/pull/12959
2025-03-17[Bug #21185] Fix Range#overlap? with infinite rangeJérôme Parent-Lévesque
Infinite ranges, i.e. unbounded ranges, should overlap with any other range which wasn't the case in the following example: (0..3).overlap?(nil..nil) Notes: Merged: https://github.com/ruby/ruby/pull/12937
2025-03-07[Bug #21174] [Bug #21175] Fix `Range#max` on beginless integer rangeNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12879
2025-01-13[Bug #21030] Fix step for non-numeric rangeNobuyoshi Nakada
When the end points of an inclusive range equal, `Range#step` should yields the element once. Notes: Merged: https://github.com/ruby/ruby/pull/12559
2025-01-02[DOC] Exclude 'Class' and 'Module' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2025-01-02[DOC] Exclude 'Method' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2024-12-10[Bug #20936] Fix #size for Range#reverse_eachKouhei Yanagita
Notes: Merged: https://github.com/ruby/ruby/pull/12301
2024-10-09Fix spellingJohn Bampton
Notes: Merged: https://github.com/ruby/ruby/pull/11835
2024-10-03[DOC] Add missing wordPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11769
2024-10-03[DOC] Add pound sign before all <=> methodsPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11769
2024-09-18[DOC] Fix formatting for ways to create Range objectsPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11641
2024-09-13[Bug #20725] Should not call compare on `nil`-endpointNobuyoshi Nakada
It means unbounded, always inclusive of other ranges. Notes: Merged: https://github.com/ruby/ruby/pull/11609
2024-09-09Return back legacy Range#step behavior for symbol rangeszverok
Notes: Merged: https://github.com/ruby/ruby/pull/11573
2024-09-03Range#step: restore legacy behavior for String rangeszverok
Notes: Merged: https://github.com/ruby/ruby/pull/11454
2024-08-19Single letter ASCII operator is same as the corresponding IDNobuyoshi Nakada
2024-08-18Make Range#step to consistently use + for iteration (#7444)Victor Shepelev
Make Range#step to consistently use + for iteration [Feature #18368] Previously, non-numerics expected step to be integer, and iterated with begin#succ, skipping over step value steps. Since this commit, numeric and non-numeric iteration behaves the same way, by using + operator. Notes: Merged-By: zverok <[email protected]>
2024-07-17[DOC] Fix and improve array slicing example in range.cIskren
* [DOC] Fix typo in range.c In the example of the beginless range used for array slicing, '..' range literal was used while the '...' literal was expected * [DOC] Add example for array slicing in range.c Add an example for the array slice with the beginless range using the '..' range literal * [DOC] Add comments for array slicing in range.c Add comments to make crystal clear what the '..' and '...' range literals do when used for array slicing as beginless range Notes: Merged: https://github.com/ruby/ruby/pull/11150 Merged-By: nobu <[email protected]>
2024-04-10[Misc #18984] Raise TypeError from Range#size if the range is not iterableKouhei Yanagita
2024-03-04[Bug #20324] Uncomparable ranges are not overlappingNobuyoshi Nakada
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-12Replace assert with RUBY_ASSERT in range.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-12-27[DOC] Fix invalid syntax in Range#eql?Peter Zhu
2023-12-22[Bug #19977] Fix (nil..nil) === x not to raise TypeErrorKouhei Yanagita
2023-12-14[DOC] Adjust some new features wording/examples. (#9183)Victor Shepelev
* Reword Range#overlap? docs last paragraph. * Docs: add explanation about Queue#freeze * Docs: Add :rescue event docs for TracePoint * Docs: Enhance Module#set_temporary_name documentation * Docs: Slightly expand Process::Status deprecations * Fix MatchData#named_captures rendering glitch * Improve Dir.fchdir examples * Adjust Refinement#target docs
2023-12-09[DOC] Small fixes for documentation renderingVictor Shepelev
Mostly just fixing RDoc's incorrect treatment of `+`
2023-11-28Make Range#reverse_each raise TypeError if endlessKouhei Yanagita
2023-11-16[DOC] More on JSON extensions (#8898)Burdette Lamar
2023-10-13describe the assumption for Range#overlap?.Tanaka Akira
Range#overlap? assumes that there is no minimum value. This assumption makes +(...-Float::INFINITY).overlap?((...-Float::INFINITY))+ returns true while +(...-Float::INFINITY)+ is empty.
2023-10-12Add Range#reverse_each implementation for performanceKouhei Yanagita
2023-10-05Optimize `Range#count` by using `range_size` if possibleKouhei Yanagita
2023-09-27[DOC] Missing comment markersNobuyoshi Nakada
2023-09-26Optimize Range#bsearch by reducing the number of Integer#+ callsKouhei Yanagita
2023-09-21Optimize Range#bsearch for beginless/endless ranges within FixnumKouhei Yanagita
2023-09-16Fix regression when testing inclusion in unbounded rangesJeremy Evans
Caused by 04a92a6764bf678919cf4b68a27496a39d6b886a. This treats unbounded ranges of arbitrary objects the same as how unbounded string ranges are treated: (..x) === y # (y <=> x) <= 0 (...x) === y # (y <=> x) < 0 (x..) === y # (x <=> y) <= 0 Fixes [Bug #19864]
2023-09-16Add comment markers in empty lines [ci skip]Nobuyoshi Nakada
2023-09-16[Feature #19839] Fix `Range#overlap?` for empty rangesNobuyoshi Nakada
Empty ranges do not overlap with any range. Regarding benchmarks, PR#8242 is significantly faster in some cases, but one of these two cases is a wrong result. | |ActiveSupport| PR#8242|built-ruby| |:--------------------------|------------:|-------:|---------:| |(2..3).overlap?(1..1) | 7.761M| 15.053M| 32.368M| | | -| 1.94x| 4.17x| |(2..3).overlap?(2..4) | 25.720M| 55.070M| 21.981M| | | 1.17x| 2.51x| -| |(2..3).overlap?(4..5) | 7.616M| 15.048M| 21.730M| | | -| 1.98x| 2.85x| |(2..3).overlap?(2..1) | 25.585M| 56.545M| 32.786M| | | -| 2.21x| 1.28x| |(2..3).overlap?(0..1) | 7.554M| 14.755M| 32.545M| | | -| 1.95x| 4.31x| |(2..3).overlap?(...1) | 6.681M| 5.843M| 32.255M| | | 1.14x| -| 5.52x| |(2...3).overlap?(..2) | 6.676M| 5.817M| 21.572M| | | 1.15x| -| 3.71x| |(2...3).overlap?(3...) | 7.392M| 14.755M| 31.805M| | | -| 2.00x| 4.30x| |(2..3).overlap?('a'..'d') | 3.675M| 3.482M| 17.009M| | | 1.06x| -| 4.89x|
2023-09-16[Feature #19839] Add Range#overlap?Shouichi Kamiya
Add a method that returns true if two range overlap, otherwise false. ``` (0..10).overlap?(5..15) #=> true (0..10).overlap?(20..30) #=> false ```
2023-09-16Optimize Range#bsearch for beginless/endless rangesKouhei Yanagita
On Range#bsearch for endless ranges, we try positions at `begin + 2**i` (i = 0, 1, 2, ...) to find a point that satisfies a given condition. Subsequently, we perform binary searching with the interval `[begin, begin + 2**n]`. However, the interval `[begin + 2**(n-1), begin + 2**n]` is sufficient for binary search because `begin + 2**(n-1)` does not satisfy the condition. The same applies to beginless ranges.
2023-04-14[Bug #19533] Fix infinite range inclusion with numeric valueNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7574
2023-04-14Extract range type check functionsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7574
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 <[email protected]>
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 <[email protected]>
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