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

1046 Коммитов

Автор SHA1 Сообщение Дата
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Koichi Sasada fa0279d947 should not share same `def` for specialized method
Because the key of redefine table is `def`, `def` should be
unique for each optimized method (`alias` is not allowed).
2021-07-29 00:56:48 +09:00
Burdette Lamar c1741df1a1 What's Here for Numeric and Comparable 2021-06-21 10:38:16 -07:00
Nobuyoshi Nakada e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
Jeremy Evans 8b00bfb7c2
Do not allow array modifications after freeze inside sort!
If freezing an array inside sort!, previously the array could be
modified after the freeze.  This checks whether the receiver is
frozen after every yield and potential call to #> or #<,
preventing modifications if the receiver is frozen inside the
block or by the #> or #< call.

Fixes [Bug #17739]
2021-05-21 18:33:56 -07:00
Masataka Pocke Kuwabara e3e5596782 Fix example code in Array#max doc
`[0, 1, 2, 3].max(6)` actually returns `[3, 2, 1, 0]`, but the doc said
it returns `[3, 2, 1]`.
2021-05-08 09:41:08 -04:00
Peter Zhu 3ca291c9ae Correctly update array capacity after realloc
Reallocating to a smaller size in the transient heap may result in no
change in the actual capacity but the capacity of the array is still
updated to the smaller value.

This commit changes `ary_heap_realloc` to return the new capacity which
can be used by the caller to correctly update the capacity.
2021-05-04 11:46:23 -04:00
Yusuke Endoh fb04c69418
array.c (rb_ary_zip): take only as many as needed from an Enumerator (#4389)
[Bug #17814]
2021-04-21 13:02:29 +09:00
Travis Hunter 55d91a096a Add Array#intersect? 2021-04-16 16:06:36 +09:00
Nobuyoshi Nakada f46bbb2e99
[DOC] Improve an example of Array#count comparison [ci skip] 2021-03-29 11:35:38 +09:00
Kenichi Kamiya 813c3333a9 [Doc] Fix Array#count comparing strategy 2021-03-28 14:17:52 -04:00
Nobuyoshi Nakada e019dd24df
Ensure the receiver is modifiable before shrinking [Bug #17736]
* Ensure the receiver is modifiable before shinking [Bug #17736]

* Assert the receivers are not modified
2021-03-20 19:15:38 +09:00
Nobuyoshi Nakada e8b210542b
Define rb_to_array which converts with to_a 2021-02-12 12:15:57 +09:00
Nobuyoshi Nakada 947d93b715
[DOC] {Array,MatchData}#values_at understand ranges [ci skip] 2021-02-07 10:30:43 +09:00
Masaki Matsushita e1e61e256b Improve performance of Array#- when it is called with empty array
This change make Array#- return a copy of the receiver when
the other array is empty.
2021-02-06 17:23:16 +09:00
Nobuyoshi Nakada 94fb62e4a0
[DOC] Fixed a markup in Array#sum [ci skip] 2021-02-06 13:40:50 +09:00
BurdetteLamar 383685b52b Explicit references to Enumerable 2021-01-20 09:33:41 -08:00
Marc-Andre Lafortune fad9922d84 Revert "[Document][Array] Add missing call-seq for Array#append"
This reverts commit ac1a4bccbd.

See https://github.com/ruby/ruby/pull/4088
2021-01-18 11:05:05 -05:00
Juanito Fatas ac1a4bccbd [Document][Array] Add missing call-seq for Array#append 2021-01-18 09:39:30 -05:00
Burdette Lamar a2941d7134
Add What's Here to Array RDoc (#4062)
* Add What's Here to Array RDoc
2021-01-15 12:08:01 -06:00
Victor Shepelev 5253b9579a
Document usage of ArithmeticSequence in Array#slice, and add to NEWS (#3952) 2020-12-21 09:32:30 +09:00
Jeremy Evans 05313c914b Use category: :deprecated in warnings that are related to deprecation
Also document that both :deprecated and :experimental are supported
:category option values.

The locations where warnings were marked as deprecation warnings
was previously reviewed by shyouhei.

Comment a couple locations where deprecation warnings should probably
be used but are not currently used because deprecation warning
enablement has not occurred at the time they are called
(RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K).

Add assert_deprecated_warn to test assertions.  Use this to simplify
some tests, and fix failing tests after marking some warnings with
deprecated category.
2020-12-18 09:54:11 -08:00
Koichi Sasada 344ec26a99 tuning trial: newobj with current ec
Passing current ec can improve performance of newobj. This patch
tries it for Array and String literals ([] and '').
2020-12-07 08:28:36 +09:00
Koichi Sasada 8247b8edde should not use rb_ary_modify()
ractor_copy() used rb_ary_modify() to make sure this array is not
sharing anything, but it also checks frozen flag. So frozen arrays
raises an error. To solve this issue, this patch introduces new
function rb_ary_cancel_sharing() which makes sure the array does not
share another array and it doesn't check frozen flag.
[Bug #17343]

A test is quoted from https://github.com/ruby/ruby/pull/3817
2020-12-01 13:18:32 +09:00
Nobuyoshi Nakada b958e2add8 Removed canonicalization for mathn 2020-11-10 11:14:15 +09:00
S-H-GAMELINKS 8b3653b484 Fix links 2020-11-10 11:04:00 +09:00
Jeremy Evans 2a294d499b
Make Array methods return Array instances instead of subclass instances
This changes the following methods to return Array instances instead
of subclass instances:

* Array#drop
* Array#drop_while
* Array#flatten
* Array#slice!
* Array#slice/#[]
* Array#take
* Array#take_while
* Array#uniq
* Array#*

Fixes [Bug #6087]
2020-11-03 14:01:38 -08: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
Burdette Lamar 54fb8fb62a
Comply with guide for method doc: array.c (#3506)
Methods:

    any?
    all?
    one?
    none?
    sum
    shuffle!
    shuffle
    sample
2020-09-02 14:02:34 -05:00
Burdette Lamar 94430d009a
Comply with guide for method doc: array.c (#3499)
Methods considered:

    count
    flatten!
    flatten
    cycle
    permutation
    combination
    repeated_permutation
    repeated_combination
    product
    take
    take_while
    drop
    drop_while
2020-09-01 12:49:48 -05:00
Burdette Lamar 50736f127a
Comply with guide for method doc: array.c (#3489)
Methods considered:

    &
    intersection
    |
    union
    max
    min
    minmax
    uniq!
    uniq
    compact!
    compact
2020-08-31 16:25:11 -05:00
Burdette Lamar e744d4070c
Comply with guide for method doc: array.c (#3484)
Methods:

    +
    concat
    *
    assoc
    rassoc
    ==
    eql?
    hash
    include?
    <=>
    -
    difference
2020-08-31 14:53:54 -05:00
Burdette Lamar 1f4c507afb
Comply with guide for method doc: array.c (#3477)
Methods considered:

    delete_at
    slice!
    reject!
    reject
    delete_if
    zip
    transpose
    replace
    clear
    fill
2020-08-31 13:16:10 -05:00
Burdette Lamar 585a659b1e
Comply with guide for method doc: array.c (#3475)
Methods considered:

    bsearch
    bsearch_index
    sort_by!
    collect
    collect!
    values_at
    select
    select!
    keep_if
    delete
2020-08-30 10:34:13 -05:00
Burdette Lamar 726f2e59f9
Comply with guide for method doc: array.c (#3474)
Methods considered:

    length
    empty?
    join
    inspect
    to_a
    to_h
    to_ary
    reverse!
    reverse
    rotate!
    rotate
    sort!
    sort
2020-08-29 15:16:02 -05:00
Burdette Lamar f0ad5594bf
Comply with guide for method doc: array.c (#3473)
Methods considered:

    at
    first
    last
    fetch
    index
    rindex
    []
    insert
    each
    each_index
    reverse_each
2020-08-29 12:15:06 -05:00
Burdette Lamar 45c40f5631
Comply with guide for method doc: array.c (#3469)
Methods:
- freeze
- try_convert
- new
- \<<
- push
- pop
- shift
- unshift
- []
2020-08-28 14:56:02 -05:00
Burdette Lamar 1d3e87a28c
Remove checks for self returned in array.c and hash.c examples (#3446)
Further compliance with https://github.com/ruby/ruby/blob/master/doc/method_documentation.rdoc#details-and-examples-
2020-08-23 12:10:01 -05:00
Burdette Lamar ea4ccc0992
Remove trivial examples from array.c (#3442)
"Trivial" typically means "returns a new empty Array."
2020-08-21 15:50:56 -05:00
Burdette Lamar b6c7b94b1c
Remove nil-return examples from array.c (#3437) 2020-08-20 20:40:26 -05:00
Burdette Lamar 63d213eb13
Partial compliance with doc/method_documentation.rdoc (#3431)
Removes references to *-convertible thingies.
2020-08-19 16:26:40 -05:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons.  We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
2020-08-15 12:09:26 +09:00
Burdette Lamar c84ccf1a07
Fix links to Dig Methods document (#3421)
* Fix links to Dig Methods document

* Fix links to Dig Methods document
2020-08-14 18:55:04 -05:00
Burdette Lamar 22fd617aa5
Adding doc/dig_methods.rdoc and links to it (#3416)
Adds a full discussion of #dig, along with links from Array, Hash, Struct, and OpenStruct.

CSV::Table and CSV::Row are over in ruby/csv. I'll get to them soon.

The art to the thing is to figure out how much (or how little) to say at each #dig.
2020-08-13 13:16:27 -05:00
卜部昌平 1f9e25cd02 MAYBE_UNUSED should just suffice
This reverts commit c355fa72d4.
2020-08-13 10:14:20 +09:00
Burdette Lamar c303e21d52
Enhanced RDoc for Array (#3400)
Methods:

    drop
    drop_while
    any?
    all?
    none?
    one?
2020-08-10 11:33:31 -05:00
Nobuyoshi Nakada 0ca6b973e8
Removed non-ASCII code to suppress warnings by localized compilers 2020-08-10 19:46:13 +09:00
Nobuyoshi Nakada c355fa72d4
Suppress unused-function warnings
Calls with a constant argument should be optimized away.
2020-08-10 17:47:34 +09:00
Burdette Lamar 4126a979ae
Enhanced RDoc for Array#take and Array#take_while (#3398) 2020-08-07 12:08:36 -05:00
Burdette Lamar 615b7fa557
Enhanced RDoc for Array#product (#3395) 2020-08-07 06:52:37 -05:00
Burdette Lamar e0bc436d9c
Enhanced documentation for Array#repeated_combination (#3392)
* Enhanced documentation for Array#repeated_combination

* Enhanced documentation for Array#repeated_combination
2020-08-05 14:58:16 -05:00
Burdette Lamar 2498334614
Enhanced documentation for Array#repeated_permutation (#3390)
* Enhanced documentation for Array#repeated_permutation

* Enhanced documentation for Array#repeated_permutation
2020-08-05 09:42:58 -05:00
Nobuyoshi Nakada b6e6807993
Initialize memo pointer and use it consistently to silence gcc 7+ 2020-08-01 15:04:58 +09:00
Burdette Lamar eebb1de7c1
Enhanced RDoc for Array 2020-07-31 19:29:34 -07:00
Jeremy Evans a6bfc951aa Document Array#flatten{,!} accept explicit nil argument [ci skip]
Fixes [Bug #10475]
2020-07-30 12:39:54 -07:00
Marc-Andre Lafortune 1b1ea7b3bc Fix Array#flatten for recursive array when given positive depth [Bug #17092] 2020-07-30 09:53:42 -04:00
Burdette Lamar 35e5b8fb82
Enhanced RDoc for Array (#3372) 2020-07-29 18:25:24 -04:00
BurdetteLamar e1b6e1d126 Enhanced RDoc for Array [ci skip] 2020-07-28 12:01:46 -07:00
Kazuhiro NISHIYAMA 946cd6c534
Use https instead of http 2020-07-28 19:51:54 +09:00
Burdette Lamar 5d04ac6ea2
Enhanced RDoc for Array (#3350)
* Enhanced RDoc for Array

Methods:

    ==
    eql?
    hash
    include?
    <=>
2020-07-22 19:06:49 -05:00
BurdetteLamar a50750c8a9 Enhanced RDoc for Array 2020-07-21 17:07:12 -05:00
BurdetteLamar d29de7b31b Enhanced RDoc for Array 2020-07-21 17:07:12 -05:00
BurdetteLamar 8a974e0fcb Enhanced RDoc for Array 2020-07-21 17:07:12 -05:00
Kenta Murata b4e784434c
Optimize Array#min (#3324)
The benchmark result is below:

|                |compare-ruby|built-ruby|
|:---------------|-----------:|---------:|
|ary2.min        |     39.105M|   39.442M|
|                |           -|     1.01x|
|ary10.min       |     23.995M|   30.762M|
|                |           -|     1.28x|
|ary100.min      |      6.249M|   10.783M|
|                |           -|     1.73x|
|ary500.min      |      1.408M|    2.714M|
|                |           -|     1.93x|
|ary1000.min     |    828.397k|    1.465M|
|                |           -|     1.77x|
|ary2000.min     |    332.256k|  570.504k|
|                |           -|     1.72x|
|ary3000.min     |    338.079k|  573.868k|
|                |           -|     1.70x|
|ary5000.min     |    168.217k|  286.114k|
|                |           -|     1.70x|
|ary10000.min    |     85.512k|  143.551k|
|                |           -|     1.68x|
|ary20000.min    |     43.264k|   71.935k|
|                |           -|     1.66x|
|ary50000.min    |     17.317k|   29.107k|
|                |           -|     1.68x|
|ary100000.min   |      9.072k|   14.540k|
|                |           -|     1.60x|
|ary1000000.min  |     872.930|    1.436k|
|                |           -|     1.64x|

compare-ruby is 9f4b7fc82e.
2020-07-18 23:45:25 +09:00
Kenta Murata a63f520971
Optimize Array#max (#3325)
The benchmark result is below:

|                |compare-ruby|built-ruby|
|:---------------|-----------:|---------:|
|ary2.max        |     38.837M|   40.830M|
|                |           -|     1.05x|
|ary10.max       |     23.035M|   32.626M|
|                |           -|     1.42x|
|ary100.max      |      5.490M|   11.020M|
|                |           -|     2.01x|
|ary500.max      |      1.324M|    2.679M|
|                |           -|     2.02x|
|ary1000.max     |    699.167k|    1.403M|
|                |           -|     2.01x|
|ary2000.max     |    284.321k|  570.446k|
|                |           -|     2.01x|
|ary3000.max     |    282.613k|  571.683k|
|                |           -|     2.02x|
|ary5000.max     |    145.120k|  285.546k|
|                |           -|     1.97x|
|ary10000.max    |     72.102k|  142.831k|
|                |           -|     1.98x|
|ary20000.max    |     36.065k|   72.077k|
|                |           -|     2.00x|
|ary50000.max    |     14.343k|   29.139k|
|                |           -|     2.03x|
|ary100000.max   |      7.586k|   14.472k|
|                |           -|     1.91x|
|ary1000000.max  |     726.915|    1.495k|
|                |           -|     2.06x|
2020-07-18 23:45:00 +09:00
Burdette Lamar 3b96ad9b54
Enhanced RDoc for Array#fill (#3301)
* Enhanced RDoc for Array#fill

* Update array.c

There's one more at 5072.  I'll get it.

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>
2020-07-11 08:01:56 -05:00
Burdette Lamar 9fc25811d5
Enhanced RDoc for Array (#3282)
Methods:

    reject!
    reject
    delete_if
    zip
    transpose
    replace
    clear
2020-07-08 09:27:10 -05:00
Burdette Lamar e8010c7401
Enhanced RDoc for Array (#3276)
*Methods:

    keep_if
    delete
    delete_at
    slice!
2020-07-03 09:49:36 -05:00
卜部昌平 4f2425549a rb_ary_slice_bang: 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
卜部昌平 73f98d25eb ary_join_1: 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
卜部昌平 4dc83eefce rb_ary_aset: 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
卜部昌平 2d6f8db3d6 add spaces [ci skip] 2020-06-29 11:05:41 +09:00
卜部昌平 86c869fb59 ary_ensure_room_for_unshift: 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
卜部昌平 2e8d8d10f2 rb_ary_behead: 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
Burdette Lamar 5e860ed4c1
[ci skip] Enhanced RDoc for Array (#3252)
Methods:

    map/collect
    map!/collect!
    values_at
    select/filter
    select!/filter!
2020-06-24 13:31:42 -05:00
Burdette Lamar dc351ff984
[ci skip] Enhanced RDoc for Array (#3237)
Methods:

    #rotate!
    #rotate
    #sort!
    #sort
    #bsearch
    #bsearch_index
2020-06-23 08:58:26 -05:00
Burdette Lamar a5bc0b8f8c
[ci skip] Enhanced RDoc for Array (#3224)
Methods:

    #to_a
    #to_h
    #to_ary
    #reverse!
    #reverse
2020-06-18 08:30:04 -05:00
Nobuyoshi Nakada b8804010fb
Remove non-US-ASCII characters [ci skip] 2020-06-14 23:59:48 +09:00
Burdette Lamar 8b58f1d8c7
[ci skip] Enhanced RDoc for Array (#3219)
Methods:

    #join
    #inspect/#to_s
    #to_a
2020-06-13 09:14:17 -05:00
Burdette Lamar eabdad5e2f
[ci skip] Enhanced Rdoc for Array (#3216)
Methods:

    #insert
    #each
    #each_index
    #reverse_each
    #length
    #empty?
2020-06-12 11:32:31 -05:00
Burdette Lamar eb5ecc2ea8
Enhanced Rdoc for Array#rindex and Array#[]= (#3204)
* Enhanced Rdoc for Array#rindex and Array#[]=

* Enhanced Rdoc for Array#rindex and Array#[]=
2020-06-11 10:55:11 -05:00
Burdette Lamar 8d4b259408
Enhanced Rdoc for Array#fetch and Array#index (#3202)
* Enhanced Rdoc for Array#fetch and Array#index
* Couple of tweaks (per review) in Rdoc for Hash
2020-06-10 06:45:29 -05:00
Burdette Lamar b85b866300
Enhanced Rdoc for Array (#3193)
Methods:

    #freeze
    #<<
    #push
    #pop
    #shift
    #unshift
    #slice
    #at
    #first
    #last
2020-06-09 13:57:41 -05:00
Masataka Pocke Kuwabara a3f498e44c
Fix max, min, minmax documentation (#3131)
They only need that all objects implement <=>,
but the documentation said it needs Comparable.
2020-05-26 23:48:46 -07:00
Kenta Murata f4f157fc81
Suppress warnings no inline ruby debug (#3107)
* Suppress unused warnings occurred due to -fno-inline

* Suppress warning occurred due to RUBY_DEBUG=1
2020-05-22 13:49:08 +09:00
S-H-GAMELINKS 1f063abb4c add static modifier to rb_ary_aref2 func 2020-05-19 15:22:53 +09:00
Burdette Lamar 24739c62e5
[ci skip] Rdoc enhancements for Array (#3063)
* Per @nobu review

* Rdoc enhancements for Array

* Responses to review
2020-05-15 14:12:40 -07:00
卜部昌平 32623150cd reroute redefinition of NDEBUG
NDEBUG can be defined via a command-line argument.  Should take care of
such situations.
2020-04-21 13:07:19 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 5b287481be
Removed non-RUBY_INTEGER_UNIFICATION code 2020-03-21 16:59:55 +09:00
卜部昌平 2325017477 fix compile error w/ -DUSE_TRANSIENT_HEAP=0
rb_transient_heap_managed_ptr_p is available only when USE_TRANSIENT_HEAP.
Need #if guards.
2020-03-04 12:30:42 +09:00
Chelsea Corvus (Battell) 672213ef1c
Document that Array#index and find_index are aliases [ci skip] 2020-02-25 13:43:17 -05:00
Nobuyoshi Nakada d4e1d4e94e
Moved Array#sample to rbinc 2020-01-26 19:45:58 +09:00
Nobuyoshi Nakada 29eb1b1602
Moved Array#shuffle and Array#shuffle! to rbinc 2020-01-26 19:40:34 +09:00
Nobuyoshi Nakada 0c436bbfbf
Recheck array length after `to_str` conversion
https://hackerone.com/reports/244787
2020-01-25 14:06:38 +09:00
Nobuyoshi Nakada 2b2821acd3
Recheck elements type after `to_str` conversion
https://hackerone.com/reports/244786
2020-01-25 13:57:33 +09:00
Ary Borenszweig e5c441a4a2 Optimize Array#rotate!(n) for n = 1 and n = -1
For the most common cases of `rotate!` one place to the right or to the
left, instead of doing some reversals of the array we just keep a single
value in a temporary value, use memmove and then put the temporary
value where it should be.
2019-12-29 13:12:42 +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
卜部昌平 0e8219f591 make functions static
These functions are used from within a compilation unit so we can
make them static, for better binary size.  This changeset reduces
the size of generated ruby binary from 26,590,128 bytes to
26,584,472 bytes on my macihne.
2019-11-19 12:36:19 +09:00