Array#find is an optimized version of Enumerable#find for arrays,
using direct index access instead of each iterator.
Array#rfind finds from the end of the array, returning the first
match when scanning backwards.
Both methods support the ifnone parameter for default values.
Co-authored-by: Claude <noreply@anthropic.com>
Merged the separate "Array#-" and "Array#- with large arrays" test
blocks into a single comprehensive test. The unified test covers both
basic functionality (type checking, simple subtraction) and the
hash-based implementation for large arrays (>32 elements).
Co-authored-by: Atlassian Rovo Dev
Implement new method for Ruby 2.7+ pattern matching compatibility.
Returns the array itself to enable case/in pattern matching syntax.
Complements Hash#deconstruct_keys for complete pattern matching support.
Co-authored-by: Atlassian Rovo Dev
Moved Array#fetch from Ruby to C using hybrid implementation for
better performance. The C implementation handles all non-block cases
with unified API that eliminates Ruby conditional logic.
Key improvements:
- Fast C implementation for common cases (no blocks)
- Shared index normalization helper reusable for other methods
- Unified C call eliminates NONE sentinel comparison in Ruby
- Block cases use C helper for index normalization
Added comprehensive test coverage including edge cases, default values,
block handling, and error message format verification. Combined tests
to focus on functionality rather than implementation details.
Co-authored-by: Atlassian Rovo Dev
This commit also corrects the behavior of `Array#insert` when a negative
index is out of bounds. It now raises an `IndexError`, which is
consistent with CRuby.
Co-authored-by: Gemini <gemini@google.com>
Implemented shared C argument parser and separate fill logic to eliminate code
duplication while maximizing performance. The implementation uses C implemented
__fill_parse_args for unified argument handling and __fill_exec for fast
C-based value filling.
Added comprehensive test coverage for both shared argument parsing
and C fill implementation, including range arguments, block handling,
and array extension scenarios.
Co-authored-by: Atlassian Rovo Dev
Co-authored-by: Gemini <gemini@google.com>
We have more chance to avoid hash allocation in set-like methods. Since
memory situation heavily depends on the platform, we may need to make
this threshold configurable in the future.
Co-authored-by: Atlassian Rovo Dev
Moved Array#intersect? implementation from Ruby to C to improve memory
usage and performance with early termination optimization. The C
implementation uses hash-based lookup for large arrays (>16 elements)
and linear search for smaller arrays.
Added comprehensive test coverage including early termination scenarios,
empty arrays, size optimization verification, and edge cases with
duplicates and large arrays.
Co-authored-by: Atlassian Rovo Dev
Moved Array#& (set intersection) implementation from Ruby to C to improve
memory usage and performance. The C implementation uses hash-based
deduplication for large arrays (>16 elements) and linear search for
smaller arrays, following the same hybrid pattern as Array#| and Array#-.
Key improvements:
- Hash-based approach uses mrb_hash_delete_key() for proper deduplication
- Linear search approach checks result array to ensure uniqueness
- Maintains order preservation from the first array
- Eliminates temporary object creation in Ruby implementation
Added comprehensive test coverage for both small and large array scenarios,
including edge cases like no intersection, complete intersection, and
duplicate handling.
Co-authored-by: Atlassian Rovo Dev
The C implementation uses hash-based deduplication for large arrays
(>16 elements) and linear search for smaller arrays, following the same
pattern as other set operations.
Co-authored-by: Atlassian Rovo Dev
Refactor Array#- to a C implementation for improved memory and performance,
especially for set operations. Uses a hybrid approach for efficiency.
Co-authored-by: Gemini <gemini@google.com>
`Object.const_defined?(:Enumerator)` is always false because
`mruby-enumerator` is not specified in `test_dependency`. I don't
think this test is necessary.
Before this patch:
$ bin/mruby -e '[1].permutation(-1){|v| p v}' #=> [1]
After this patch (same as Ruby):
$ bin/mruby -e '[1].permutation(-1){|v| p v}' #=> no output