Skip to content

Avoid an array allocation per element in list passed to seplist #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

jeremyevans
Copy link
Contributor

The array allocation was because the keyword splat expression is not recognized as safe by the compiler. Also avoid unnecessary >= method call per element. This uses a private constant to avoid unnecessary work at runtime.

I assume the only reason this code is needed is because v may end with a ruby2_keywords hash that we do not want to treat as keywords.

This issue was found by the performance warning in Ruby feature 21274.

The array allocation was because the keyword splat expression is
not recognized as safe by the compiler.  Also avoid unnecessary
>= method call per element.  This uses a private constant to
avoid unnecessary work at runtime.

I assume the only reason this code is needed is because v may
end with a ruby2_keywords hash that we do not want to treat as
keywords.

This issue was found by the performance warning in Ruby feature
21274.
lib/pp.rb Outdated
}
end
EMPTY_HASH = if RUBY_VERSION >= "3.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about EMPTY_KWHASH ?
EMPTY_HASH is not an empty hash in ruby < 3.0. This hash can't be used for a purpose other than empty keyword splat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, renaming the constant is fine. I'll push a commit for that.

@tompng tompng merged commit 6c230d9 into ruby:master Apr 22, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants