Skip to content

Avoid array allocation in DSL::Parameters#with#2672

Open
ericproulx wants to merge 3 commits intomasterfrom
ruby_optimizations
Open

Avoid array allocation in DSL::Parameters#with#2672
ericproulx wants to merge 3 commits intomasterfrom
ruby_optimizations

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

@ericproulx ericproulx commented Apr 3, 2026

Summary

  • Replace [@group, opts].compact.reduce(&:deep_merge) with @group&.deep_merge(opts) || opts
  • Avoids allocating a temporary array on every with block call
  • Uses safe navigation operator for a more idiomatic form
  • No behavior change (Hash#deep_merge always returns a Hash)

Test plan

  • bundle exec rspec spec/grape/dsl/parameters_spec.rb — 23 examples, 0 failures

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Danger Report

No issues found.

View run

@ericproulx ericproulx force-pushed the ruby_optimizations branch 4 times, most recently from de2fbcb to f152893 Compare April 4, 2026 11:33
Replace five specific exception classes (EmptyMessageBody, TooManyMultipartFiles,
TooDeepParameters, ConflictingTypes, InvalidParameters) with a single
Grape::Exceptions::RequestError that forwards the Rack exception message directly.

On Rack 3.1.0, a single `rescue Rack::BadRequest` covers all bad-request errors via
the marker module. Before, each exception class is listed explicitly in
Grape::RACK_ERRORS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the ruby_optimizations branch from f152893 to b2f64ee Compare April 5, 2026 21:51
ericproulx and others added 2 commits April 6, 2026 00:04
Replace redundant `key: key` kwargs with the shorthand `key:` form
where the local variable name matches the keyword argument name.

Enforce the style through Rubocop

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the ruby_optimizations branch from b2f64ee to 7e295ef Compare April 5, 2026 22:06
@dblock
Copy link
Copy Markdown
Member

dblock commented Apr 6, 2026

rebase?

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