summaryrefslogtreecommitdiff
path: root/range.c
AgeCommit message (Collapse)Author
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
2020-07-19Special case Range#max for integer beginning and Float::Infinity endJeremy Evans
Popular Ruby libraries such as Rails and Rubocop relying on the previous behavior, even though it is technically a bug. The correct behavior is probably raising RangeError, since that is what an endless range raises. Related to [Bug #17017]
2020-07-19Fix Range#max for beginless Integer ranges [Bug #17034]Michael Kohl
* Fix Range#max for beginless Integer ranges * Update test/ruby/test_range.rb * Fix formatting https://github.com/ruby/ruby/pull/3328 Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged-By: nobu <nobu@ruby-lang.org>
2020-07-13Fix Range#{max,minmax} for range with integer beginning and non-integer endJeremy Evans
Previously, for inclusive ranges, the max would show up as the end of the range, even though the end was not an integer and would not be the maximum value. For exclusive ranges, max/minmax would previously raise a TypeError, even though it is possible to get the correct maximum. This change to max/minmax also uncovered a similar error in cover?, which calls max in certain cases, so adjust the code there so that cover? still works as expected. Fixes [Bug #17017] Notes: Merged: https://github.com/ruby/ruby/pull/3306 Merged-By: jeremyevans <code@jeremyevans.net>
2020-07-04Use static variables in Range#minmaxJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/3286
2020-07-04Fix non-numeric exclusive Range#minmax bugSam Bostock
The implementation of Range#minmax added in d5c60214c45 causes the following incorrect behaviour: ('a'...'c').minmax => ["a", ["a", "b"]] instead of ('a'...'c').minmax => ["a", "b"] This is because the C implementation of Range#minmax (range_minmax) directly delegates to the C implementation of Range#min (range_min) and Range#max (range_max), without changing the execution context. Range#max's C implementation (range_max), when given a non-numeric exclusive range, delegates to super, which is meant to call Enumerable#max. However, because range_max is called directly by range_minmax, super calls Enumerable#minmax instead, causing the incorrect nesting. Perhaps it is possible to change the execution context in an optimized manner, but the simplest solution seems to be to just explicitly delegate from Range#minmax to Range#min and Range#max. Notes: Merged: https://github.com/ruby/ruby/pull/3285
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29range_each: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-04-08Suppress -Wswitch warningsNobuyoshi Nakada
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-02-07more on NULL versus functions.卜部昌平
Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-25range.c: Range#min with a beginless one now raise an explicit exceptionYusuke Endoh
[Bug #16450]
2019-12-22Enhance Range docszverok
* Change === docs to mention it uses cover? * Add different example to === docs to showcase behavior better * Change include? docs to mention cover? and clarify the difference Notes: Merged: https://github.com/ruby/ruby/pull/2768
2019-12-20Fixed misspellingsNobuyoshi Nakada
Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
2019-12-04implement Range#count卜部昌平
As matz requested in [Bug #16366].
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-08-14Make Range#=== operate like cover? instead of include? for string rangesJeremy Evans
Previously, Range#=== treated string ranges that were not endless or beginless the same as include?, instead of the same as cover?. I think this was an oversight in 989e07c0f2fa664a54e52a475c2fcc145f06539d, as the commit message did not indicate this behavior was desired. This also makes some previously dead code no longer dead. Previously, the conditionals were doing this: if (RB_TYPE_P(beg, T_STRING) if (NIL_P(beg)) # can never be true This restructures it so at the NIL_P(beg) check, beg could possibly be nil (beginless ranges). Fixes [Bug #15449]
2019-08-14Implement Range#minmaxJeremy Evans
Range#minmax was previous not implemented, so calling #minmax on range was actually calling Enumerable#minmax. This is a simple implementation of #minmax by just calling range_min and range_max. Fixes [Bug #15867] Fixes [Bug #15807]
2019-07-24Document that Range#cover? returns false if <=> returns nilJeremy Evans
Fixes [Bug #12090]
2019-05-23range.c (inspect_range): omit beginless "nil"Yusuke Endoh
except the special case `(nil..nil)`. ``` (1..).inspect #=> "1.." (..5).inspect #=> "..5" (nil..nil).inspect #=> "nil..nil" ``` [Bug #15745]
2019-05-01Add exception support in `Range#first`.manga_osyo
Closes: https://github.com/ruby/ruby/pull/2163
2019-04-08range.c: force hash values fixablenobu
* range.c (range_hash): force hash values fixable on LLP64 environment. [ruby-core:92194] [Bug #15757] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-04range.c: support to make beginless arithmetic sequencesmrkn
* range.c (range_step): fix the guard condition so that a beginless range can be turned into a beginless arithmetic sequence. * test/ruby/test_range.rb (test_step): add assertions for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-03range.c (r_cover_range_p): support beginless rangemame
`(..2).cover?(..1)` should return true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-03Introduce beginless range [Feature#14799]mame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28[DOC] fix markups [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09Fix styles [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-08range.c (range_last): disable optimization when each is redefinedmrkn
Do not use the optimized version of Range#last when Range#each is redefined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-06range.c: optimize rb_range_last for int renagemrkn
This change improves the performance of Range#last method for a range of integer. This optimization directly computes only required values only in a range instead of converting all values in the range to an array. The optimized implementation is 129-16.7k times faster than the previous one in the benchmark result given below. === Benchmark Result === ``` $ make benchmark ITEM=range_last COMPARE_RUBY=/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby generating known_errors.inc known_errors.inc unchanged /Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged /Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \ --executables="compare-ruby::/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby -I.ext/common --disable-gem" \ --executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \ $(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*range_last*.yml' -o -name '*range_last*.rb' | sort) Warming up -------------------------------------- (1..1_000_000).last(100) 35.600 i/s - 36.000 times in 1.011239s (28.09ms/i) (1..1_000_000).last(1000) 36.204 i/s - 39.000 times in 1.077240s (27.62ms/i) (1..1_000_000).last(10000) 36.470 i/s - 39.000 times in 1.069386s (27.42ms/i) Calculating ------------------------------------- compare-ruby built-ruby (1..1_000_000).last(100) 36.477 609.196k i/s - 106.000 times in 2.905950s 0.000174s (1..1_000_000).last(1000) 35.936 50.350k i/s - 108.000 times in 3.005321s 0.002145s (1..1_000_000).last(10000) 35.641 4.602k i/s - 109.000 times in 3.058233s 0.023685s Comparison: (1..1_000_000).last(100) built-ruby: 609195.7 i/s compare-ruby: 36.5 i/s - 16700.87x slower (1..1_000_000).last(1000) built-ruby: 50349.7 i/s compare-ruby: 35.9 i/s - 1401.08x slower (1..1_000_000).last(10000) built-ruby: 4602.1 i/s compare-ruby: 35.6 i/s - 129.12x slower ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-21range.c: reject ArithmeticSequence in rb_range_valuesmrkn
Reject ArithmeticSequence in rb_range_values so that methods like Array#[] raises TypeError for ArithmeticSequence as an index. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12range.c: [DOC] fix typostomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12range.c: Typo fix [DOC] [ci skip] [#15405]marcandre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12range.c: Documentation on endless ranges.marcandre
Based on patch by Victor Shepelev [DOC] [#7552] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12enumerator.c: rb_arithmetic_sequence_extractmrkn
New public C-API for extracting components of Enumerator::ArithmeticSequence or Range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Prefer rb_check_arity when 0 or 1 argumentsnobu
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12range.c: [DOC] improve docs for Range#cover?stomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e