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

340 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada fb17c833f5 [Bug #19533] Fix infinite range inclusion with numeric value 2023-04-14 10:22:09 +09:00
Nobuyoshi Nakada 1a149aab77 Extract range type check functions 2023-04-14 10:22:09 +09:00
BurdetteLamar 3b239d2480 Remove (newly unneeded) remarks about aliases 2023-02-19 14:26:34 -08:00
Nobuyoshi Nakada da4464b824
[Bug #19426] Fix endless `Range#step` with `#succ` method 2023-02-09 20:37:34 +09:00
Marco Costa d2847009db
[DOC] Fix most of Range#cover? marked as verbatim 2022-12-23 11:12:16 +09:00
Daniel Colson e69b91fae4 Introduce BOP_CMP for optimized comparison
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>
2022-12-06 12:37:23 -08:00
Jeremy Evans 04a92a6764 Raise TypeError for endless non-numeric range include?
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]
2022-11-24 15:18:44 -08:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Yusuke Endoh e026368061 Range#size returns nil for (.."a") and (nil..)
Fixes [Bug #18983]
2022-10-21 16:35:46 +09:00
Jean Boussier bbe5ec7846 rb_int_range_last: properly handle non-exclusive range
[Bug #18994]
2022-09-04 11:16:11 +02:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Jeremy Evans c5475f4269 Fix Range#cover? returning true for beginless ranges of different types
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]
2022-06-06 09:59:22 -07:00
Jeremy Evans f8724987db Document beginless, endless ranges in Range class documentation 2022-04-25 13:07:35 -07:00
Burdette Lamar ffcdbedbfb
Repaired What's Here sections for Range, String, Symbol, Struct (#5735)
Repaired What's Here sections for Range, String, Symbol, Struct.
2022-03-30 13:46:24 -05:00
Nobuyoshi Nakada 50c972a1ae
[DOC] Simplify operator method references 2022-02-12 12:38:36 +09:00
Jeremy Evans fd710d7e99 Fix Range#include? for beginless exclusive string ranges
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]
2022-02-09 19:47:28 -08:00
Nobuyoshi Nakada 8ca7b0b68a
[DOC] Fix broken links to operator methods
Once https://github.com/ruby/rdoc/pull/865 is merged, these hacks
are no longer needed.
2022-02-08 01:39:37 +09:00
Nobuyoshi Nakada 16fdc1ff46
[DOC] Fix broken links to literals.rdoc 2022-02-08 01:27:52 +09:00
Peter Zhu a32e5e1b97 [DOC] Use RDoc link style for links in the same class/module
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
2022-02-07 09:52:06 -05:00
Peter Zhu f9a2802bc5 [DOC] Use RDoc link style for links to other classes/modules
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
2022-02-07 09:52:06 -05:00
Burdette Lamar 28fb6d6b9e
Adding links to literals and Kernel (#5192)
* Adding links to literals and Kernel
2021-12-03 07:12:28 -06:00
S.H 75aae66c4f
Some codes replace to `RBOOL` macro (#5023)
* Some code replace and using RBOOL macro

* Fix indent

* Using RBOOL in syserr_eqq function
2021-11-09 17:09:29 +09:00
Nobuyoshi Nakada 4fb71575e2
[DOC] Fix code markup [ci skip]
Code markup in RDoc must not be concatenated with anothr word.
2021-10-25 01:04:51 +09:00
Nobuyoshi Nakada e2017f8c7c
Unify iteration arguments 2021-10-10 11:45:50 +09:00
Nobuyoshi Nakada 2293547d9b
Update iteration step in step_i_iter 2021-10-10 11:41:26 +09:00
S.H afb95d1004
Refactor sym_step_i function 2021-10-10 11:40:04 +09:00
S.H dc9112cf10
Using NIL_P macro instead of `== Qnil` 2021-10-03 22:34:45 +09:00
Jörg W Mittag fb03598666
Remove unnecessary checks in `Range#each` [Bug #18237]
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.
2021-10-03 22:16:08 +09:00
Burdette Lamar 854fe9d1c1
Correct two errors in Range RDoc (#4889) 2021-09-23 18:08:49 -05:00
Burdette Lamar fb976df81f
What's Here for Range (#4881) 2021-09-22 14:51:11 -05:00
Burdette Lamar 736eb30e52
Enhanced RDoc for Range (#4870)
Introductory material revised.
2021-09-20 13:41:55 -05:00
Burdette Lamar 1c07c98229
Enhanced RDoc for Range (#4847)
Treated:

    #to_s
    #inspect
    #===
    #include?
    #cover?
    #count
2021-09-18 07:27:02 -05:00
Burdette Lamar 745287d43a
Enhanced RDoc for Range#minmax (#4846) 2021-09-15 15:51:54 -05:00
Burdette Lamar e967740d07
Enhanced RDoc for Range#max (#4844) 2021-09-15 14:48:47 -05:00
Burdette Lamar 97374c7eec
Enhanced RDoc for Range#min (#4842) 2021-09-15 13:37:34 -05:00
Nobuyoshi Nakada a27c274f04
[DOC] Fix broken links [ci skip]
* 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.
2021-09-15 14:16:14 +09:00
Burdette Lamar a0357acf19
Enhanced RDoc for Range (#4839)
Treated:

    #size
    #to_a
    #each
    #begin
    #end
    #first
    #last
2021-09-14 17:51:31 -05:00
Burdette Lamar 1af5a0c574
Bsearch doc for Array and Range (#4838)
This PR creates doc/bsearch.rdoc to provide common documentation for bsearch in Array and Range.
2021-09-14 16:08:21 -05:00
Burdette Lamar 4e03032a83
Enhanced RDoc for Range (#4833)
Treated:

    ::new
    #include_end?
    #==
    #eql?
    #hash
    #step
2021-09-13 14:00:39 -05:00
S-H-GAMELINKS 83a5e2bb5c Using RB_FLOAT_TYPE_P macro 2021-09-12 11:16:31 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
S-H-GAMELINKS e882905d0d Refactor sym_each_i function 2021-07-22 14:02:23 +09:00
Aaron Patterson 9f3adaf529 Use public allocators for creating new T_OBJECT objects
This way the header flags and object internals are set correctly
2020-10-28 18:35:22 -07:00
Kenta Murata f754b42285
numeric.c, range.c: prohibit zero step
* numeric.c: prohibit zero step in Numeric#step

* range.c: prohibit zero step in Range#step

* Fix ruby-spec

[Feature #15573]
2020-10-23 15:26:51 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Kenta Murata a6a8576e87
Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)
* 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]
2020-10-21 02:40:18 +09:00
Kenta Murata 18cecda46e
range.c: Fix an exception message in rb_range_beg_len
[Bug #17271]
2020-10-20 16:01:57 +09:00
Koichi Sasada 0096d2b895 freeze all Range objects.
Matz want to try to freeze all Range objects.
[Feature #15504]
2020-09-25 22:16:55 +09:00
Nobuyoshi Nakada 6321330461
Removed trailing spaces [ci skip] 2020-09-02 13:30:16 +09:00
Jeremy Evans de10a1f358 Update documentation for Range#max 2020-09-01 10:52:47 -07:00