Skip to content

Commit 41dced0

Browse files
authored
Merge pull request #1940 from dnesteryuk/chore/micro-optimization-2
get rid of a needless step in HashWithIndifferentAccess
2 parents 69ce0df + 7ed7598 commit 41dced0

File tree

6 files changed

+10
-25
lines changed

6 files changed

+10
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Features
44

55
* Your contribution here.
6+
* [#1940](https://github.com/ruby-grape/grape/pull/1940): Get rid of a needless step in HashWithIndifferentAccess - [@dnesteryuk](https://github.com/dnesteryuk).
67
* [#1938](https://github.com/ruby-grape/grape/pull/1938): Add project metadata to the gemspec - [@orien](https://github.com/orien).
78
* [#1920](https://github.com/ruby-grape/grape/pull/1920): Replace Virtus with dry-types - [@dnesteryuk](https://github.com/dnesteryuk).
89

lib/grape/dsl/inside_route.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def should_be_empty_array?(declared_param, passed_children_params)
8484
end
8585

8686
def declared_param_is_array?(declared_param)
87-
route_options_params[declared_param.to_s] && route_options_params[declared_param.to_s][:type] == 'Array'
87+
key = declared_param.to_s
88+
route_options_params[key] && route_options_params[key][:type] == 'Array'
8889
end
8990

9091
def route_options_params

lib/grape/endpoint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def mount_in(router)
154154
methods << Grape::Http::Headers::HEAD
155155
end
156156
methods.each do |method|
157-
unless route.request_method.to_s.upcase == method
157+
unless route.request_method == method
158158
route = Grape::Router::Route.new(method, route.origin, route.attributes.to_h)
159159
end
160160
router.append(route.apply(self))

lib/grape/extensions/active_support/hash_with_indifferent_access.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ def params_builder
1414
end
1515

1616
def build_params
17-
params = ::ActiveSupport::HashWithIndifferentAccess[rack_params]
17+
params = ::ActiveSupport::HashWithIndifferentAccess.new(rack_params)
1818
params.deep_merge!(grape_routing_args) if env[Grape::Env::GRAPE_ROUTING_ARGS]
19-
# TODO: remove, in Rails 4 or later ::ActiveSupport::HashWithIndifferentAccess converts nested Hashes into indifferent access ones
20-
DeepHashWithIndifferentAccess.deep_hash_with_indifferent_access(params)
19+
params
2120
end
2221
end
2322
end

lib/grape/extensions/deep_hash_with_indifferent_access.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/grape/router/route.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ def route_path
6262
end
6363

6464
def initialize(method, pattern, **options)
65+
upcased_method = method.to_s.upcase
66+
6567
@suffix = options[:suffix]
66-
@options = options.merge(method: method.to_s.upcase)
68+
@options = options.merge(method: upcased_method)
6769
@pattern = Pattern.new(pattern, **options)
68-
@translator = AttributeTranslator.new(**options, request_method: method.to_s.upcase)
70+
@translator = AttributeTranslator.new(**options, request_method: upcased_method)
6971
end
7072

7173
def exec(env)

0 commit comments

Comments
 (0)