Replace block.call(x) with yield x in core iteration methods to take
advantage of the new OP_BLKCALL optimization. This improves Integer#times
by 13% and Array#each by 7%.
Methods updated:
- Integer#times, Integer#upto, Integer#downto
- Array#each, Array#each_index
Co-authored-by: Claude <noreply@anthropic.com>
added parentheses to all `to_enum` and `super` calls where the return
value is used (returned, assigned, or passed to another method). this
makes the code style consistent with the guideline that method calls
should use parentheses when their return values are consumed.
changes:
- return to_enum :symbol -> return to_enum(:symbol)
- return to_enum :symbol, arg -> return to_enum(:symbol, arg)
- super message, name -> super(message, name)
affected files: 10error.rb, array.rb, enum.rb, hash.rb, kernel.rb,
numeric.rb, range.rb
Co-authored-by: Claude <noreply@anthropic.com>
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)
Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.
Co-authored-by: Atlassian Rovo Dev
Array#to_a now properly converts subclasses to Array objects. For example,
'class A<Array;end; p A.new(1,2).to_a.class' now returns Array, not A.
Co-authored-by: Atlassian Rovo Dev
- use heap sort (O(1)) instead of merge sort (O(n)) for better space
complexity.
- method implemented in C for better performance
As a result, simple sorting now consumes far less memory and is faster.
Since it's implemented in C, fiber context switching is not allowed from
comparison, but we consider the risk is minimal (no one switches context
in the comparison, right?)
The ISO standard does not include implicit type conversion using
`to_int`. This implicit conversion often causes vulnerability.
There will be no more attacks like #4120.
In addition, we have added internal convenience method `__to_int` which
does type check and conversion (from floats).
Example benchmark:
$ time build/bench/bin/mruby -e "Array.new(2_000_000){ |i| i }.index{ |i| i == 1_999_999 }"
Before:
real 0m0.934s
user 0m0.922s
sys 0m0.003s
After:
real 0m0.590s
user 0m0.583s
sys 0m0.007s
Dr Markus Kuhn published in 1999 an article [1] explaining in details
why we shouldn't use the ASCII grave accent (0x60) as a left quotation.
Backticks have been used most notably to produce nice-looking LaTeX
documents but it doesn't seem to be an issue on modern platforms and
for the oldest ones, there are workarounds as mentioned by Dr Kuhn.
[1]: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html