rb_range_component_beg_len() converts range endpoints used as indices, and Range#first, #last and #max take element counts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Once rb_len_t widens this changes the `long *` output parameters of rb_range_beg_len(), rb_str_subpos(), rb_arithmetic_sequence_beg_len_step(), ruby_enc_find_basename() and ruby_enc_find_extname(), so extensions passing `long *` to them will need to be updated. The extension guides list these signatures verbatim and follow along.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit centralizes shape setting for objects in the ZJIT GC fastpath
into the rb_zjit_new_obj_shape function to avoid each type having to deal
with shapes individually.
The Range Marshal compat dumper would allocate
an Object with no size information, hence get a 32B slot
with enough space for 2 ivars, then insert 3 ivars causing
it to spill.
This isn't a big problem, but somewhat shows that the interface
isn't WVA aware.
By introducing `rb_class_allocate_instance_capa` we can directly
allocate an object with enough room.
Benchmark:
i = 0
def run(max)
i = 0
while i < max
a = i..100
i += 1
end
end
30.times { run(2) }
run(10_000_000)
Result:
Benchmark 1: master
Time (mean ± σ): 229.8 ms ± 3.2 ms [User: 221.7 ms, System: 6.2 ms]
Range (min … max): 226.3 ms … 235.2 ms 12 runs
Benchmark 2: branch
Time (mean ± σ): 67.4 ms ± 2.0 ms [User: 60.4 ms, System: 5.3 ms]
Range (min … max): 65.1 ms … 75.1 ms 43 runs
Summary
branch ran
3.41 ± 0.11 times faster than master
THe downside is that we now always reserve one 8B reference for the
IMEMO/fields, even for structs that never have any ivars.
But it is an acceptable tradeoff given that ivars on structs aren't
rare.
Co-Authored-By: John Hawthorn <john@hawthorn.email>
* 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:
These two class are most common sources of infinite sequences. This change should effectively prevent accidental infinite loops when calling to_set on them. [Bug #21513]
Small correction to the Range docs. All beginless (nil..) and endless (..nil) ranges, as well as fully open ranges (nil..nil), display "nil..nil" when inspected, regardless of their original syntax.
Make Range#step to consistently use + for iteration [Feature #18368]
Previously, non-numerics expected step to be integer,
and iterated with begin#succ, skipping over step value
steps. Since this commit, numeric and non-numeric iteration
behaves the same way, by using + operator.
* [DOC] Fix typo in range.c
In the example of the beginless range used for array slicing,
'..' range literal was used while the '...' literal was expected
* [DOC] Add example for array slicing in range.c
Add an example for the array slice with the beginless range
using the '..' range literal
* [DOC] Add comments for array slicing in range.c
Add comments to make crystal clear what the '..' and '...'
range literals do when used for array slicing as beginless range
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
Range#overlap? assumes that there is no minimum value.
This assumption makes
+(...-Float::INFINITY).overlap?((...-Float::INFINITY))+ returns true
while +(...-Float::INFINITY)+ is empty.