1288 Commits
Author SHA1 Message Date
Takashi Kokubun 7ba583d753 merge revision(s) c27ae8d91a, b6e6ccc6c2, cbca59377e: [Backport #21844]
[ruby/psych] Remove excessive check of message

	Make `Data#initialize` reject `Integer` keys

	[Bug #21844] Fix error message
2026-04-03 20:20:44 -07:00
Victor Shepelev ec4ca91319 Small documentation adjustments for new/updated features (#15634)
* Document Range#to_set

* Update Thread#raise and Fiber#raise signatures and docs

* Add reference to String#strip to character_selectors.rdoc

* Update *nil docs when calling methods

* Enhance Array#find and #rfind docs

* Add a notice to Kernel#raise about cause:
2025-12-20 13:07:38 +02:00
Étienne Barrié 769c6a1c54 [DOC] Use Arrays in examples for Array#find 2025-12-17 21:22:39 -08:00
Étienne Barrié bb0e42c5e7 Define Array#detect as an alias for Array#find
Otherwise Array#detect is Enumerable#detect while Array#find uses a
different more performant implementation.

[Feature #21678]
2025-12-15 10:52:43 -05:00
Kevin Newton 6147b69587 Array#rfind
Implement Array#rfind, which is the same as find except from the
other side of the Array. Also implemented Array#find (as opposed to
the generic one on Enumerable because it is significantly faster
and to keep the implementations together.

[Feature #21678]
2025-12-12 13:35:30 -05:00
Luke Gruber a211abbcbd Cache array length in rb_ary_join (#15362)
When all elements are strings, we never have to recalculate the length
of the array because there are no conversion methods that are called, so
the length will never change. This speeds up the fast path by ~10%.

```ruby
a = ["1"*10, "2"*10, "3"*10, "4"*10, "5"*10] * 10
10_000_000.times do
  a.join
end
```

```
hyperfine --warmup 1 'ruby ../ruby2/test.rb' './exe/ruby ../ruby2/test.rb'
Benchmark 1: ruby ../ruby2/test.rb
  Time (mean ± σ):      3.779 s ±  0.053 s    [User: 3.754 s, System: 0.017 s]
  Range (min … max):    3.715 s …  3.874 s    10 runs

Benchmark 2: ./exe/ruby ../ruby2/test.rb
  Time (mean ± σ):      3.411 s ±  0.038 s    [User: 3.387 s, System: 0.017 s]
  Range (min … max):    3.360 s …  3.472 s    10 runs

Summary
  ./exe/ruby ../ruby2/test.rb ran
    1.11 ± 0.02 times faster than ruby ../ruby2/test.rb
```
2025-12-02 17:35:53 -05:00
Nobuyoshi Nakada f92ff9a86b Remove an excess semicolon in a macro 2025-12-01 07:15:36 +09:00
Stan Lo 4cd6661e18 Reorganize page documentations (#15154)
Re-organize page docs
2025-11-27 20:12:24 +00:00
Peter Zhu 2380f69f68 Fix array allocation when slot size < 40 bytes
We need to allocate at least sizeof(struct RArray) when the array is
embedded on garbage collectors that support slot sizes less than 40 bytes.
2025-11-02 09:17:17 -05:00
Koichi Sasada bc00c4468e use SET_SHAREABLE
to adopt strict shareable rule.

* (basically) shareable objects only refer shareable objects
* (exception) shareable objects can refere unshareable objects
  but should not leak reference to unshareable objects to Ruby world
2025-10-23 13:08:26 +09:00
Ricardo Trindade 42ba82424d Fix typo in comment in array#zip docs
Duplicate the was found in the documentation
2025-10-07 18:54:34 -04:00
Peter Zhu 2d57e9e2a1 Clear out memory for newly allocated array 2025-09-17 09:25:17 -04:00
Peter Zhu 5a946a5be2 Change order of RARRAY_AREF and ARY_SET_LEN in rb_ary_pop
We should access the last element first before we shrink the length of the
array.
2025-09-11 08:14:25 -04:00
Ethan 60ca525fce [DOC] Array#map! fix to indicate return is self 2025-08-09 11:10:51 +09:00
Ethan 4209ebb1e4 [DOC] Array#fill fix to indicate return is self
doc currently indicates the return value as `new_array` but then in the first sentence explains "always returns +self+ (never a new array)".
2025-08-09 11:10:51 +09:00
Jean Boussier 45a2c95d0f Reduce exposure of FL_FREEZE
The `FL_FREEZE` flag is redundant with `SHAPE_ID_FL_FROZEN`, so
ideally it should be eliminated in favor of the later.

Doing so would eliminate the risk of desync between the two, but
also solve the problem of the frozen status being global in namespace
context (See Bug #21330).
2025-06-24 11:29:39 +01:00
Zopolis4 915d027738 Fix typo (newsString -> new String) 2025-05-11 07:07:10 +09:00
Nobuyoshi Nakada ce8f7da49e [Bug #21304] Reload length and pointer after #hash method
The receiver can be modified during the method calls.
2025-05-04 12:40:33 +00:00
Yusuke Endoh f3246ccebb Fix an ASAN error in Array#difference
[Bug #21303]
2025-05-04 02:20:42 +09:00
Samuel Williams c13ac4d615 Assert the GVL is held when performing various rb_ functions.
[Feature #20877]
2025-04-14 18:28:09 +09:00
Nobuyoshi Nakada d31c15d81f [DOC] Reference to the idiom from Array#sort 2025-02-27 13:07:43 +09:00
Jean Boussier 9826047f01 Array#sort_by! return early if sorting is useless
`Array#sort!` does that check, but `#sort_by!` always tries to
sort, which is wasteful.
2025-02-13 11:38:02 +01:00
Peter Zhu e603a420e9 [DOC] Fix call-seq consistency in Array
The documentation guide (https://docs.ruby-lang.org/en/master/contributing/documentation_guide_md.html#label-Calling+Sequence+-28for+methods+written+in+C-29)
says that the call-seq for instance methods should only include the method
name, no prepending `array.`.
2025-02-10 16:30:04 -05:00
Nobuyoshi Nakada 8dd0d63550 [Bug #21106] Remove the useless last iteration
When only one element remains, this simply swaps the first identical
element and has no actual effect.
2025-02-02 19:34:52 +09:00
BurdetteLamar f349104259 [DOC] Tweaks for Array doc 2025-01-03 11:42:53 -05:00
Nobuyoshi Nakada e433e6515e [DOC] Exclude 'Class' and 'Module' from RDoc's autolinking 2025-01-02 12:36:06 +09:00
Nobuyoshi Nakada b4ec22fe6c [DOC] Exclude 'Method' from RDoc's autolinking 2025-01-02 12:23:49 +09:00
tomoya ishida 477c505ac0 [DOC] Fix output examples containing old Hash#inspect format
The inspect format was intentionally changed as an outcome of
[Bug #20433] [ruby-core:118668], but some documentation update
was missing, as [Bug #20962] pointed out. Update some output
examples that clearly use Hash#inspect.
2024-12-18 12:08:15 -05:00
Kouhei Yanagita 25602421fb [DOC] Fix the block parameter name in Array#zip 2024-12-18 11:00:36 +09:00
Burdette Lamar 50a67820fb [DOC] Change arg names from n to count (#12288) 2024-12-17 10:55:43 -05:00
Stan Lo 211857f48f Fix incorrect rdoc-ref links in array.rb 2024-12-13 18:09:39 -05:00
Jean Boussier 5335b140ab array.c: Remove unused rb_ary_verify function 2024-12-05 09:16:31 +01:00
Jean Boussier bf225feb26 Fix an off by one in rb_ary_resize
When setting len to X we only need to grow the array
if len is bigger than capa. If they're equal we don't need to
increase capacity.
2024-12-04 22:46:02 +01:00
BurdetteLamar d588a1c880 Correct order of listed methods 2024-12-02 15:28:53 -05:00
BurdetteLamar 9db056f2ea [DOC] Tweaks for Array 2024-11-20 10:40:49 -05:00
Takashi KokubunandAaron Patterson c9a5a71695 Move Array#select to Ruby
Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2024-11-13 12:27:26 -08:00
6deeec5d45 Mark strings returned by Symbol#to_s as chilled (#12065)
* Use FL_USER0 for ELTS_SHARED

This makes space in RString for two bits for chilled strings.

* Mark strings returned by `Symbol#to_s` as chilled

[Feature #20350]

`STR_CHILLED` now spans on two user flags. If one bit is set it
marks a chilled string literal, if it's the other it marks a
`Symbol#to_s` chilled string.

Since it's not possible, and doesn't make much sense to include
debug info when `--debug-frozen-string-literal` is set, we can't
include allocation source, but we can safely include the symbol
name in the warning message, making it much easier to find the source
of the issue.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>

---------

Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-11-13 09:20:00 -05:00
BurdetteLamar 6a3eb384ce [DOC] Tweaks for array indexes 2024-11-11 11:23:00 -05:00
BurdetteLamar 071d0eca8e [DOC] Sort items in What's Here 2024-11-11 11:21:13 -05:00
BurdetteLamar 3ac5c05327 [DOC] Tweaks for Array#| 2024-11-11 09:43:30 -05:00
Burdette Lamar 72550d269e [DOC] Doc for Array#zip (#11961) 2024-11-08 14:56:44 -05:00
Burdette Lamar 0193f6c288 [DOC] Doc for Array#values_at (#11960) 2024-11-06 22:19:42 -05:00
Takashi Kokubun 478e0fc710 YJIT: Replace Array#each only when YJIT is enabled (#11955)
* YJIT: Replace Array#each only when YJIT is enabled

* Add comments about BUILTIN_ATTR_C_TRACE

* Make Ruby Array#each available with --yjit as well

* Fix all paths that expect a C location

* Use method_basic_definition_p to detect patches

* Copy a comment about C_TRACE flag to compilers

* Rephrase a comment about add_yjit_hook

* Give METHOD_ENTRY_BASIC flag to Array#each

* Add --yjit-c-builtin option

* Allow inconsistent source_location in test-spec

* Refactor a check of BUILTIN_ATTR_C_TRACE

* Set METHOD_ENTRY_BASIC without touching vm->running
2024-11-04 11:14:28 -05:00
Burdette Lamar a8f220ed90 [DOC] Tweaks for Array#uniq (#11949) 2024-10-28 10:05:49 -04:00
Burdette Lamar 05f894aba2 [DOC] Tweaks for Array#uniq! (#11950) 2024-10-25 10:52:22 -04:00
BurdetteLamar 2b98545646 [DOC] Tweaks for Array#union 2024-10-24 17:25:04 -04:00
BurdetteLamar 2078ba1984 [DOC] Tweaks for Array#transpose 2024-10-24 17:23:22 -04:00
Burdette Lamar da82b84b55 [DOC] Tweaks for Array#inspect (#11935) 2024-10-22 15:20:58 -04:00
BurdetteLamar 00af6a3f04 [DOC] Tweaks for Array#to_h 2024-10-22 15:11:26 -04:00
Burdette Lamar 9cbf2f5fff [DOC] Tweaks for Array#take_while (#11930) 2024-10-22 12:36:12 -04:00