1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refector a bit to remove extra slice iteration and splat call

This yields a small bit of performance improvement when building the
defaults from constraints, specially considering that it's rather common
for constraints to be empty.

Also, there's a bit of duplicated code in here that I have to check
before extracting.
This commit is contained in:
Carlos Antonio da Silva 2012-11-24 08:48:01 -02:00
parent d98014cbcb
commit ccdf54d6fc

View file

@ -252,7 +252,7 @@ module ActionDispatch
def defaults_from_constraints(constraints) def defaults_from_constraints(constraints)
url_keys = [:protocol, :subdomain, :domain, :host, :port] url_keys = [:protocol, :subdomain, :domain, :host, :port]
constraints.slice(*url_keys).select{ |k, v| v.is_a?(String) || v.is_a?(Fixnum) } constraints.select { |k, v| url_keys.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) }
end end
end end
@ -858,7 +858,7 @@ module ActionDispatch
def defaults_from_constraints(constraints) def defaults_from_constraints(constraints)
url_keys = [:protocol, :subdomain, :domain, :host, :port] url_keys = [:protocol, :subdomain, :domain, :host, :port]
constraints.slice(*url_keys).select{ |k, v| v.is_a?(String) || v.is_a?(Fixnum) } constraints.select { |k, v| url_keys.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) }
end end
end end