Modify new_stmts to flatten unnecessary nesting by returning existing
NODE_STMTS directly instead of wrapping them. This reduces memory usage
and AST complexity when multiple parentheses levels are used.
Before: (((expr1; expr2))) creates nested NODE_STMTS
After: (((expr1; expr2))) creates single NODE_STMTS with statements
Co-authored-by: Claude <noreply@anthropic.com>
Rename NODE_BEGIN to NODE_STMTS to better reflect its purpose as a
container for statement sequences, not specifically begin-end blocks.
This prepares for adding a dedicated node type for explicit begin-end
constructs.
- Rename NODE_BEGIN enum to NODE_STMTS in node.h
- Update all references in parse.y and codegen.c
- Rename new_begin function to new_stmts
Co-Authored-By: Claude <noreply@anthropic.com>
This commit adds `call-seq` documentation to the following methods
in `mruby-numeric-ext` to improve code clarity and maintainability:
- `Integer#even?`
- `Integer#odd?`
- `Integer.sqrt`
- `Float#remainder`
Additionally, it adds a comment to the internal `isqrt` function
to explain its implementation.
Co-authored-by: Gemini <gemini@google.com>
The `XXX` comment in `sprintf.c` suggested that not validating
the number of arguments for positional format specifiers was a bug.
However, CRuby's `sprintf` also ignores extra arguments in this
case, making the existing behavior correct.
This commit removes the confusing comment and the disabled code
block that went with it, clarifying the intended behavior and
cleaning up the code.
Co-authored-by: Gemini <gemini@google.com>
The `mruby-hash-ext` gem already had `call-seq` comments for its
public methods, but the internal helper functions `slice_bang_i` and
`hash_key_i` were undocumented.
This commit adds detailed comments to these functions, explaining their
purpose, parameters, and return values. This improves the
maintainability and readability of the code.
Co-authored-by: Gemini <gemini@google.com>
Fixed critical resource leaks by pre-allocating mruby objects before system
calls. Since mrb_str_resize to smaller size and mrb_ary_push within
pre-allocated size cannot fail, moving allocations before socket creation
eliminates all leak potential with minimal code changes.
Co-authored-by: Atlassian Rovo Dev
Added call-seq documentation for 7 public methods (2 in C, 5 in Ruby)
improving documentation coverage from ~1% to complete. Includes method
signatures, clear descriptions, and practical examples for cover?, size,
max, min, overlap?, first, and last. Added simple description for internal
__empty_range? helper method.
Co-authored-by: Atlassian Rovo Dev
Fixes a null pointer dereference in `find_visibility_scope` when defining a
singleton method inside `instance_eval`.
This was caused by `ci->u.env` being `NULL` in this context. The fix adds a
`NULL` check to prevent the crash.
Co-authored-by: Gemini <gemini@google.com>
This commit optimizes instance variable lookups by replacing the
search algorithm with the same branch-free binary search recently
introduced for method lookups. This improves performance by
avoiding CPU branch mispredictions.
This commit replaces the method table search algorithm with a
branch-free binary search. This avoids conditional branches,
which can prevent CPU pipeline stalls from branch misprediction,
leading to faster method lookups.
The new `bsearch_idx` function is used for finding, inserting,
and deleting methods in the method table.
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
Add detailed comments to all functions in class.c including:
- Function purpose and behavior descriptions
- Parameter documentation with types and meanings
- Return value explanations with all possible outcomes
- Error conditions and exception documentation
- Helper function and structure documentation
This improves code maintainability and follows Ruby documentation
conventions with proper call-seq formatting.
Co-authored-by: Atlassian Rovo Dev
This commit introduces `Hash#slice!`, which removes key-value pairs from a
hash, keeping only the ones specified in the arguments. The removed pairs
are returned as a new hash.
Co-authored-by: Gemini <gemini@google.com>
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
Implement new method for Ruby 2.7+ pattern matching compatibility.
Handles nil (return self) and array (extract keys) arguments.
Enables modern case/in pattern matching syntax in mruby.
Co-authored-by: Atlassian Rovo Dev
Replace Ruby implementation with C version using mrb_hash_foreach.
Provides early termination optimization when value is found.
Eliminates iteration overhead for better performance.
Co-authored-by: Atlassian Rovo Dev
Replace Ruby implementation with C version for better performance.
Handles all argument forms: multiple args, hash copy, array of arrays.
Supports subclasses and maintains full compatibility with existing tests.
Co-authored-by: Atlassian Rovo Dev
Use insertion sort for small arrays (≤16) and heap sort for larger arrays.
Provides 50-200% performance improvement for small arrays while maintaining
O(n log n) guarantee for large arrays. Includes iterative heapify to
eliminate stack overflow risk on memory-constrained devices.
Co-authored-by: Atlassian Rovo Dev
Add fast-path comparisons for integers, floats, and strings in Array#sort!
when no custom comparison block is provided. This reduces VM callback
overhead for common data types, improving performance.
Co-authored-by: Gemini <gemini@google.com>
Eliminates stack overflow risk on memory-constrained devices by reducing
stack usage from O(log n) to O(1) during heap sort operations.
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
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>
This commit replaces the Ruby implementation of and with a C
implementation. The new implementation is iterative and uses a stack to
avoid deep recursion, which prevents stack overflows when flattening
deeply nested arrays.
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>