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

ericproulx and others added 2 commits April 3, 2026 18:46
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, a single `rescue Rack::BadRequest` covers all bad-request errors via
the marker module. On Rack 2, each exception class is listed explicitly in
Grape::RACK_ERRORS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace redundant `key: key` kwargs with the shorthand `key:` form
where the local variable name matches the keyword argument name.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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 2 times, most recently from cbe0355 to bec4677 Compare April 3, 2026 17:09
Replace `[@group, opts].compact.reduce(&:deep_merge)` with
`@group&.deep_merge(opts) || opts` to avoid allocating a temporary
array on every `with` block call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the ruby_optimizations branch from bec4677 to de2fbcb Compare April 3, 2026 17:20
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.

1 participant