Browse files

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.
  • Loading branch information...
1 parent d98014c commit ccdf54d6fcc96e70a2049f9828241037156067d8 @carlosantoniodasilva carlosantoniodasilva committed Nov 24, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 actionpack/lib/action_dispatch/routing/mapper.rb
View
4 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -252,7 +252,7 @@ def default_action
def defaults_from_constraints(constraints)
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
@@ -858,7 +858,7 @@ def override_keys(child) #:nodoc:
def defaults_from_constraints(constraints)
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

0 comments on commit ccdf54d

Please sign in to comment.