Skip to content

style/performance fixes - #7086

Merged
matz merged 2 commits into
mruby:masterfrom
leviongit:style/fixes
Aug 11, 2026
Merged

style/performance fixes#7086
matz merged 2 commits into
mruby:masterfrom
leviongit:style/fixes

Conversation

@leviongit

@leviongit leviongit commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

the code under $repo/mrblib/ has been changed to use yield instead of &.call
due to the OP_BLKCALL optimization

similarly, checks of the form var.{is_a?, kind_of?}(Class) have been changed into Class === var (aside from test, and prism source)

Summary by CodeRabbit

  • Refactor

    • Standardized internal type validation across array, numeric, range, string, symbol, I/O, socket, and collection operations.
    • Streamlined block execution across enumerable, hash, numeric, range, array, and string methods.
    • Preserved existing method signatures, iteration behavior, return values, formatting, comparisons, and error handling.
  • Bug Fixes

    • Improved consistency of type handling and callback execution without changing expected application behavior.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 19a74d48-60cb-4503-a3b7-04bedcc7344e

📥 Commits

Reviewing files that changed from the base of the PR and between 7184392 and dbbe765.

📒 Files selected for processing (19)
  • mrbgems/mruby-array-ext/mrblib/array.rb
  • mrbgems/mruby-compar-ext/mrblib/compar.rb
  • mrbgems/mruby-complex/mrblib/complex.rb
  • mrbgems/mruby-enum-ext/mrblib/enum.rb
  • mrbgems/mruby-enumerator/mrblib/enumerator.rb
  • mrbgems/mruby-io/mrblib/file.rb
  • mrbgems/mruby-range-ext/mrblib/range.rb
  • mrbgems/mruby-rational/mrblib/rational.rb
  • mrbgems/mruby-socket/mrblib/socket.rb
  • mrbgems/mruby-sprintf/mrblib/string.rb
  • mrbgems/mruby-string-ext/mrblib/string.rb
  • mrbgems/mruby-symbol-ext/mrblib/symbol.rb
  • mrbgems/mruby-task/mrblib/queue.rb
  • mrblib/array.rb
  • mrblib/enum.rb
  • mrblib/hash.rb
  • mrblib/numeric.rb
  • mrblib/range.rb
  • mrblib/string.rb

📝 Walkthrough

Walkthrough

The change replaces Ruby type-predicate calls with Class === checks across library methods. It also replaces captured block calls with direct yield in collection, numeric, range, and string iteration methods.

Changes

Core Ruby library normalization

Layer / File(s) Summary
Class-check normalization
mrbgems/mruby-*/mrblib/*
mrbgem methods use class checks for arrays, ranges, numerics, strings, symbols, integers, and socket types.
Direct block yields
mrblib/array.rb, mrblib/enum.rb, mrblib/hash.rb, mrblib/numeric.rb
Collection and numeric methods invoke caller blocks with yield instead of block.call.
Range and string iteration updates
mrblib/range.rb, mrblib/string.rb
Range and string methods use direct yields. Range#each and String#each_line also use class checks.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • mruby/mruby#7001: Uses the same Class === approach for regexp and string pattern validation.

Suggested reviewers: matz

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title relates to the changes but is too broad to identify the specific style and performance updates. Use a specific title that mentions replacing block.call with yield and is_a?/kind_of? checks with Class === checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 97.87% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@matz
matz merged commit 9b0bf95 into mruby:master Aug 11, 2026
21 checks passed
@matz

matz commented Aug 11, 2026

Copy link
Copy Markdown
Member

Merged, thank you. Both halves are changes I want, and the second one is a convention I wrote into CONTRIBUTING.md a few days ago that nothing had gone back and applied.

What I checked before merging, since a sweep across nineteen files is the kind where a single bad substitution hides easily:

  • The 39 block changes are all block.call(...), none of them &.call, so nothing that was guarding against a missing block lost its guard. map, select, each_with_index, collect! and friends still return an Enumerator when called without one, and max/min still fall back to <=>.
  • The 28 type checks all kept the class on the left and the value on the right. Array === row, not the reverse.
  • Twenty rows against CRuby 4.0.6, block-present and block-absent, all agreeing. Full suite green, ASan and UBSan clean, no new warning.

One request for next time, and it is about the shape rather than the content: please split a sweep like this into one pull request per kind of change. block.call to yield and is_a? to Module#=== are independent, and each would stand alone.

The reason is collision surface rather than review effort. This landed alongside a run of unrelated work in mrblib and mrbgems/*/mrblib, and a nineteen-file diff has to be rebased whole every time any of it moves. Two smaller ones would each have moved through on their own. It also lets one be reverted without the other if something turns up later.

Nothing to change here, and I would rather have the sweep than not have it. Thank you for doing the unglamorous half of a convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants