aboutsummaryrefslogtreecommitdiffstats
path: root/range.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Special case Range#max for integer beginning and Float::Infinity endJeremy Evans2020-07-191-0/+9
| | | | | | | | | 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]
* Fix Range#max for beginless Integer ranges [Bug #17034]Michael Kohl2020-07-191-3/+4
| | | | | | | | | * 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>
* Fix Range#{max,minmax} for range with integer beginning and non-integer endJeremy Evans2020-07-131-3/+18
| | | | | | | | | | | | | 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]
* Use static variables in Range#minmaxJeremy Evans2020-07-041-2/+4
|
* Fix non-numeric exclusive Range#minmax bugSam Bostock2020-07-041-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* add UNREACHABLE_RETURN卜部昌平2020-06-291-0/+2
| | | | | | 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.
* range_each: do not goto into a branch卜部昌平2020-06-291-20/+36
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-3/+3
| | | Split ruby.h
* more on NULL versus functions.卜部昌平2020-02-071-1/+1
| | | | | | Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
* decouple internal.h headers卜部昌平2019-12-261-3/+13
| | | | | | | | | | | | | | | | | | 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).
* range.c: Range#min with a beginless one now raise an explicit exceptionYusuke Endoh2019-12-251-0/+7
| | | | [Bug #16450]
* Enhance Range docszverok2019-12-221-10/+24
| | | | | | | | * 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
* Fixed misspellingsNobuyoshi Nakada2019-12-201-2/+2
| | | | Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
* implement Range#count卜部昌平2019-12-041-0/+37
| | | | As matz requested in [Bug #16366].
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-2/+0
| | | | | | 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.
* Make Range#=== operate like cover? instead of include? for string rangesJeremy Evans2019-08-141-9/+14
| | | | | | | | | | | | | | | | | | 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]
* Implement Range#minmaxJeremy Evans2019-08-141-0/+22
| | | | | | | | | 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]
* Document that Range#cover? returns false if <=> returns nilJeremy Evans2019-07-241-1/+4
| | | | Fixes [Bug #12090]
* range.c (inspect_range): omit beginless "nil"Yusuke Endoh2019-05-231-3/+9
| | | | | | | | | | | | except the special case `(nil..nil)`. ``` (1..).inspect #=> "1.." (..5).inspect #=> "..5" (nil..nil).inspect #=> "nil..nil" ``` [Bug #15745]
* Add exception support in `Range#first`.manga_osyo2019-05-011-0/+3
| | | | Closes: https://github.com/ruby/ruby/pull/2163
* range.c: force hash values fixablenobu2019-04-081-1/+1
| | | | | | | * 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
* range.c: support to make beginless arithmetic sequencesmrkn2019-04-041-1/+3
| | | | | | | | | | * 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
* range.c (r_cover_range_p): support beginless rangemame2019-04-031-2/+3
| | | | | | `(..2).cover?(..1)` should return true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Introduce beginless range [Feature#14799]mame2019-04-031-10/+39
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] fix markups [ci skip]nobu2019-03-281-6/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix styles [ci skip]nobu2019-01-091-2/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* range.c (range_last): disable optimization when each is redefinedmrkn2019-01-081-1/+2
| | | | | | | 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
* range.c: optimize rb_range_last for int renagemrkn2019-01-061-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* range.c: reject ArithmeticSequence in rb_range_valuesmrkn2018-12-211-0/+3
| | | | | | | 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
* range.c: [DOC] fix typostomar2018-12-121-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* range.c: Typo fix [DOC] [ci skip] [#15405]marcandre2018-12-121-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* range.c: Documentation on endless ranges.marcandre2018-12-121-0/+28
| | | | | | 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
* enumerator.c: rb_arithmetic_sequence_extractmrkn2018-12-121-3/+0
| | | | | | | 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
* Prefer rb_check_arity when 0 or 1 argumentsnobu2018-12-061-6/+1
| | | | | | | 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
* range.c: [DOC] improve docs for Range#cover?stomar2018-10-121-5/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adjust indent [ci skip]nobu2018-09-281-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add Range#% to call-seq [ci skip]kazu2018-09-281-0/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e