Граф коммитов

333 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 de3e931df7 add 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.
2020-06-29 11:05:41 +09:00
卜部昌平 9c5804ac1c range_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.
2020-06-29 11:05:41 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
卜部昌平 115fec062c more on NULL versus functions.
Function pointers are not void*.  See also
ce4ea956d2
8427fca49b
2020-02-07 14:24:19 +09:00
卜部昌平 5e22f873ed decouple 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).
2019-12-26 20:45:12 +09:00
Yusuke Endoh 81e377023c range.c: Range#min with a beginless one now raise an explicit exception
[Bug #16450]
2019-12-25 13:36:23 +09:00
zverok 5a0102cb61 Enhance Range docs
* 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
2019-12-22 23:17:39 +09:00
Nobuyoshi Nakada db16629008
Fixed misspellings
Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
2019-12-20 09:32:42 +09:00
卜部昌平 00bbdf4451 implement Range#count
As matz requested in [Bug #16366].
2019-12-04 15:32:49 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Jeremy Evans 6954ff1dcb Make Range#=== operate like cover? instead of include? for string ranges
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 989e07c0f2,
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-14 14:14:49 -07:00
Jeremy Evans d5c60214c4 Implement Range#minmax
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-08-14 11:22:07 -07:00
Jeremy Evans 3556cba503 Document that Range#cover? returns false if <=> returns nil
Fixes [Bug #12090]
2019-07-24 10:35:28 -07:00
Yusuke Endoh 9d39eb6b40 range.c (inspect_range): omit beginless "nil"
except the special case `(nil..nil)`.

```
(1..).inspect      #=> "1.."
(..5).inspect      #=> "..5"
(nil..nil).inspect #=> "nil..nil"
```

[Bug #15745]
2019-05-23 00:48:32 +09:00
manga_osyo 4e88e86928 Add exception support in `Range#first`.
Closes: https://github.com/ruby/ruby/pull/2163
2019-05-01 00:03:30 +09:00
nobu ae6c195f30 range.c: force hash values fixable
* 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-08 03:26:29 +00:00
mrkn dcb37d0639 range.c: support to make beginless arithmetic sequences
* 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-04 03:34:52 +00:00
mame d4319541e8 range.c (r_cover_range_p): support beginless range
`(..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-03 08:35:57 +00:00
mame 95f7992b89 Introduce beginless range [Feature#14799]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-03 08:11:41 +00:00
nobu de0ef1a9df [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:35 +00:00
nobu 78d6e33702 Fix styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 13:58:49 +00:00
mrkn 2b9c6e1a8a range.c (range_last): disable optimization when each is redefined
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-08 04:37:40 +00:00
mrkn 6e1d498ac7 range.c: optimize rb_range_last for int renage
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
2019-01-06 00:46:36 +00:00
mrkn 7bef465e9b range.c: reject ArithmeticSequence in rb_range_values
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-21 13:05:16 +00:00
stomar 2930317b09 range.c: [DOC] fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 22:03:11 +00:00
marcandre c3fe2cb682 range.c: Typo fix [DOC] [ci skip] [#15405]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 21:45:17 +00:00
marcandre 296bd00e02 range.c: Documentation on endless ranges.
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-12 19:49:22 +00:00
mrkn 914a290324 enumerator.c: rb_arithmetic_sequence_extract
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-12 06:39:58 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
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-12-06 07:49:24 +00:00
stomar 863a2a1fc8 range.c: [DOC] improve docs for Range#cover?
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 21:11:54 +00:00
nobu a9375ab398 Adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-28 09:23:35 +00:00
kazu 41aa841a52 Add Range#% to call-seq [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-28 06:25:24 +00:00
mrkn 85f192b075 range.c: Add Range#%
[Feature #14697] [ruby-core:86588]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-28 02:18:58 +00:00
mrkn 98fa0ab4d9 [DOC] Modify descriptions for ArithmeticSequence
[ci-skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 08:51:34 +00:00
tarui 9ca7389272 range.c: Range#cover? accepts Range object. [Feature #14473]
* range.c (range_cover): add code for range argument.
          If the argument is a Range, check it is or is not 
	  covered by the reciver. If it can be treated as a
	  sequence, this method treats it that way. 
	* test/ruby/test_range.rb (class TestRange): add tests
	  for this feature.
	  
	  This patch is written by Owen Stephens. thank you!


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-05 19:06:08 +00:00
kazu 023537f883 Remove extra semicolon
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-20 15:33:59 +00:00
mrkn f15069338d enumerator.c: Introduce Enumerator::ArithmeticSequence
This commit introduces new core class Enumerator::ArithmeticSequence.
Enumerator::ArithmeticSequence is a subclass of Enumerator, and
represents a number generator of an arithmetic sequence.

After this commit, Numeric#step and Range#step without blocks
returned an ArithmeticSequence object instead of an Enumerator.

This class introduces the following incompatibilities:

- You can create a zero-step ArithmeticSequence,
  and its size is not ArgumentError, but Infinity.
- You can create a negative-step ArithmeticSequence from a range.

[ruby-core:82816] [Feature #13904]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06 09:08:28 +00:00
stomar e1a8d281eb range.c: [DOC] small improvement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-08 19:30:19 +00:00
mame cae4517419 range.c: Range#last and #max raises a RangeError if it is endless
Also, Range#min raises an error if it is endless and a comparison method
is specified.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-22 02:58:40 +00:00
mame 342619300c range.c: Range#size now returns Float::INFINITY if it is endless
Fixes [Bug #14699]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-22 02:58:39 +00:00
mame c19ecf05b4 range.c: Range#to_a now raises RangeError if it is endless
Fixes [Bug #14845]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-22 02:58:37 +00:00
mame 606d6b3470 Revert "range.c: prohibit `(1..nil)`"
This reverts commit a44c010764a16ae09aaed49d76eec055ca0057c8.
Refs #14845.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-13 11:00:28 +00:00
mame 48de2ea5f9 range.c: prohibit `(1..nil)`
Now endless range can be created by either a literal `(1..)` or explicit
range creation `Range.new(1, nil)`.  [Bug #14845]

This change is intended for "early failure"; for example,
`(1..var).to_a` causes out of memory if `var` is inadvertently nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-13 09:04:32 +00:00
nobu 989e07c0f2 range.c: === by cover?
* range.c (range_eqq): switch `Range#===` to use `cover?` instead
  of `include?`.  [Feature #14575]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-17 10:46:21 +00:00
nobu 058949ac13 range.c: optimize range_each for Bignum
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-29 07:12:56 +00:00
nobu 797d2ab5d3 range.c: endless symbol range
* range.c (range_each): shortcirtuit endless symbol range too, as
  well as `#step`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-28 23:31:32 +00:00
nobu 703a5dd3e0 string.c: adjust to rb_str_upto_each
* range.c (range_each_func): adjust the signature of the callback
  function to rb_str_upto_each, and exit the loop if the callback
  returned non-zero.

* string.c (rb_str_upto_endless_each): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-28 11:16:54 +00:00
nobu d07861fb2f range.c: each on endless range
* range.c (range_each): endless range begins with string-like
  object should iterate from the converted result string, as well
  as `#each` on a string-end range or `#step` method on an endless
  range, i.e., `begin.succ` should not be called.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-28 07:31:32 +00:00
nobu db885d0850 range.c: step in bignum
* range.c (range_step): honor step in bignum addition.
  [Feature #12912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20 00:23:01 +00:00
nobu ad5a6aa790 range.c: fix fixnum loop condition
* range.c (range_step): FIXABLE + FIXABLE never overflow, but may
  not be FIXABLE.  [Feature #12912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20 00:10:46 +00:00
k0kubun 46697c7e26 internal.h: use the same declaration as definition
range.c: cast the function type to meet the declaration

This change is for fixing build error on AppVeyor:
https://ci.appveyor.com/project/ruby/ruby/build/1.0.8177

string.c
../string.c(4330) : error C4028: formal parameter 2 different from declaration

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 16:19:48 +00:00
mame d55452cb37 Prefer CONST_ID to static global IDs
Just refactoring.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:19:00 +00:00
mame d658a8d568 range.c: Make Range#bsearch support endless ranges
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:18:57 +00:00
mame db1bdecb0d Make Range#min, max, include?, cover?, and === to support endless range
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:18:53 +00:00
mame 7f95eed19e Introduce endless range [Feature#12912]
Typical usages:
```
p ary[1..]          # drop the first element; identical to ary[1..-1]
(1..).each {|n|...} # iterate forever from 1; identical to 1.step{...}
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:18:50 +00:00
mrkn 2234edf0b1 Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of
For checking whether an object is an Integer, because a subclass of
Integer is meaningless in Ruby, RB_INTEGER_TYPE_P is better than
rb_obj_is_kind_of for speed.

* object.c (rb_to_integer): Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of.

* object.c (rb_check_to_integer): ditto.

* range.c (range_max): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-26 07:57:15 +00:00
nobu 50a99a7679 range.c: use rb_check_funcall
* range.c (rb_range_values): use rb_check_funcall instead of
  calling rb_respond_to then rb_funcall, and allow `begin` and
  `end` to be private as well as other internal conversions.
  [ruby-core:83541] [Bug #14048]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 05:23:54 +00:00
nobu 0ba049256e range.c: check if exclude_end? is defined
* range.c (rb_range_values): should raise TypeError if necessary
  method is not defined, not NoMethodError, when trying to tell if
  the object is a Range and extract info.
  [ruby-core:83541] [Bug #14048]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 01:40:15 +00:00
watson1978 ab3a40c103 Improve performance of Range#{min,max}
range.c (range_min): use OPTIMIZED_CMP() to compare the objects instead of
    `<=>' method dispatching for Fixnum/Float/String object inside Range object.

range.c (range_max): ditto.

    Range#min -> 34 % up
    Range#max -> 44 % up

    [ruby-core:80713] [Bug #13443] [Fix GH-1585]

### Before
           Range#min      8.428M (± 1.3%) i/s -     42.141M in   5.000952s
           Range#max      8.157M (± 1.3%) i/s -     40.852M in   5.009297s

### After
           Range#min     11.269M (± 1.2%) i/s -     56.388M in   5.004611s
           Range#max     11.764M (± 1.3%) i/s -     58.856M in   5.003820s

### Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Range#min" do |i|
    i.times { (1..100).min }
  end

  x.report "Range#max" do |i|
    i.times { (1..100).max }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-30 02:57:33 +00:00
nobu 6c8852c1d3 range.c: remove no longer used variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-26 00:30:05 +00:00
eregon ead61f4ac8 no longer rescue exceptions of #<=> when initializing a Range
* range.c (range_init): no longer hide the user exception
  with a ArgumentError, just let the user exception go through.
* test/ruby/test_range.rb (test_new): add tests.
  [Feature #7688]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25 11:42:43 +00:00
nobu 54bc0a446d range.c: check loading
* range.c (range_loader): check loading values if the data came
  from an initialized range object. [ruby-core:78067] [Bug #12915]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 11:52:03 +00:00
nobu 1a7aba1b47 range.c: check if range modifiable
* range.c (range_modify): frozen object cannot be modified.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-10 10:39:51 +00:00
nobu 38320caaf6 range.c: indent [ci skip]
* range.c (range_alloc): adjust indent of comments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-10 00:49:16 +00:00
hsbt 82dd08285f * range.c: Add docs for max/min behavior with exclusive range.
[fix GH-1433][ci skip] Patch by @BM5k

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-05 05:27:42 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
nobu 706534b5f5 range.c: check_step_domain
* range.c (check_step_domain): check step argument domain by <=>
  method, instead of < and >.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-25 12:33:15 +00:00
shugo 62b750bb55 * range.c (range_eqq): revert r11113 because rb_call_super() is
called in range_include() and thus r11113 doesn't work when the
  receiver Range object consists of non linear objects such as Date
  objects.
  [ruby-core:72908] [Bug #12003]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-23 11:16:09 +00:00
nobu f7fb4e00f7 range.c: infected by the receiver
* range.c (range_to_s): should be infected by the receiver.
  str2 infects by appending.  [ruby-core:71811] [Bug #11767]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-03 05:22:18 +00:00
nobu 72ff61f4a8 NameError#receiver of uninitialized constant
* error.c (name_err_mesg_to_str): quote the name if unprintable.
* object.c (check_setter_id): use rb_check_id to convert names.
* variable.c (uninitialized_constant): use NameError::message to
  keep the receiver of uninitialized constant.  [Feature #10881]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-28 06:24:12 +00:00
nobu a19830c42c range.c: call range_include directly if possible
* range.c (range_eqq): trivial optimization to jump to
  range_include directly if the method is not redefined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-15 02:30:56 +00:00
nobu 80e0ef3a81 range.c: move String specific code
* range.c (range_include): call rb_str_include_range_p on String.

* string.c (str_upto_each): extract from rb_str_upto.

* string.c (rb_str_include_range_p): move String specific code
  from Range#include? in range.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-15 12:39:56 +00:00
nobu 04c10b8af3 range.c: r_less
* range.c (r_less): merge r_le() and r_lt() and make code shorter
  with less branches.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-15 09:06:18 +00:00
nobu bad0560661 range.c: r_cover_p
* range.c (r_cover_p): extract from range_cover and share with
  range_include.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-15 09:05:57 +00:00
nobu b0616346f8 range.c: covered for linear objects
* range.c (linear_object_p, range_include): test if covered for
  linear objects.  [ruby-core:69052] [Bug #11113]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-03 01:02:15 +00:00
nobu 0238f47fa7 range.c: predefined IDs
* range.c (id_cmp, id_succ): use predefined IDs in id.def.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-01 22:39:14 +00:00
nobu 523ecd29b8 use frozen string of symbols
* range.c (range_step, range_each): String#upto should never
  modifies the receiver, use frozen strings to enumerate symbols.

* re.c (reg_operand): matching target is not modified.

* ext/socket/constants.c (constant_arg): str_to_int never modifies
  argument strings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-14 03:31:28 +00:00
nobu 16294913f7 use rb_funcallv
* use rb_funcallv() for no arguments call instead of variadic
  rb_funcall().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-16 04:08:52 +00:00
nobu b13432890f range.c: trivial optimizations
* range.c (range_bsearch): trivial optimizations, for Fixnum, and
  by keeping the last satisfied element.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13 03:51:35 +00:00
nobu 6b8b66b401 range.c: class name encoding
* range.c (range_bsearch): preserve encoding of class name in an
  exception message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13 03:47:55 +00:00
nobu 225e3b011f range.c: reduce argument evaluations
* range.c (BSEARCH_CHECK): get rid of conversion of the argument
  multiple times.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13 03:47:41 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
nobu 4a91fb7a45 range.c: unused function
* range.c (SET_EXCL): remove no longer used function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:46 +00:00
nobu fc23374f06 [DOC] add links to `Object#hash`
add links to `Object#hash` to each #`hash` methods rdocs.
[Fixes GH-567]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:43 +00:00
marcandre d4cf669da7 Range#bsearch: fix typo in rdoc
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-15 00:39:25 +00:00
akr f526784e1e * enum.c: Enumerable#{min,min_by,max,max_by} extended to take an
optional argument.
  (nmin_cmp): New function.
  (nmin_block_cmp): Ditto
  (nmin_filter): Ditto.
  (nmin_i): Ditto.
  (nmin_run): Ditto.
  (enum_min): Call nmin_run if the optional argument is given.
  (nmin_max): Ditto.
  (nmin_min_by): Ditto.
  (nmin_max_by): Ditto.

* range.c: Range#{min,max} extended to take an optional argument.
  (range_min): Call range_first if the optional argument is given.
  (range_max): Call rb_call_super if the optional argument is given.

[ruby-core:57111] [Feature #8887]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-14 15:45:11 +00:00
eregon d31cd06516 * range.c (Range#size): [DOC] improve description and add examples.
Patch by @skade. [Fixes GH-501]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 21:23:45 +00:00
nobu 6f2efe84fb hash.c: detect recursion for all
* hash.c (rb_hash): detect recursion for all `hash' methods.  each
  `hash' methods no longer need to use rb_exec_recursive().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 13:18:30 +00:00
nobu 4ce307aeee range.c: revert the old behavior
* range.c (range_each): revert the old behavior, no block is given to
  the yielded block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-30 04:21:22 +00:00
nobu 92b4a05e07 vm_eval.c: rb_yield_block
* vm_eval.c (rb_yield_block): yield block with rb_block_call_func
  arguments.
* range.c (range_each): use rb_yield_block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 08:06:19 +00:00
nobu 7566c49068 ruby/ruby.h: RB_BLOCK_CALL_FUNC_ARGLIST
* include/ruby/ruby.h (RB_BLOCK_CALL_FUNC_ARGLIST): for declaration
  argument list of rb_block_call_func.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 07:59:14 +00:00
nobu 32145ebfd6 array.c, enum.c, range.c: rb_block_call_func compatible
* array.c (take_i), range.c (first_i): make rb_block_call_func
  compatible.

* enum.c (collect_all, DEFINE_ENUMFUNCS): add blockarg.

* enum.c ({min,max,minmax,chunk,slicebefore}_ii): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 07:45:00 +00:00
nobu 9f45081627 ruby/ruby.h: add blockarg to rb_block_call_func
* include/ruby/ruby.h (rb_block_call_func): add blockarg.  block
  function can take block argument, e.g., proc {|&blockarg| ...}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 02:26:48 +00:00
nobu 94f01c55df should not ignore the rest of recursive constructs
* array.c (rb_ary_hash): should not ignore the rest of recursive
  constructs.
* hash.c (rb_hash_hash): ditto.
* range.c (range_hash): ditto.
* struct.c (rb_struct_hash): ditto.
* test/-ext-/test_recursion.rb (TestRecursion): separate from
  test/ruby/test_thread.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 17:20:16 +00:00
nobu 64f2b9f990 range.c: modify check
* range.c (range_initialize_copy): disallow to modify after
  initialized.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-26 10:08:02 +00:00
nobu a2231670d6 range.c: fix int and VALUE
* range.c (SET_EXCL): set boolean always.

* range.c (range_init): fix int flag and boolean VALUE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-25 06:57:20 +00:00
nobu a6d095bd22 range.c: setter macros
* range.c (RANGE_SET_{BEG,END,EXCL}): add setter macros which wrap
  RSTRUCT_SET() and index.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-25 05:18:26 +00:00