Permalink
Browse files

Stop as soon as we get a match

Instead of building a list of all the matches, and then picking off
the first one, just stop as soon as we find a match.
  • Loading branch information...
1 parent 9d0243b commit 60377392e5d368f4a2e7e0654030fe5e055cdd64 @tomhughes committed Feb 14, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/http_accept_language/parser.rb
@@ -55,10 +55,10 @@ def preferred_language_from(array)
# request.compatible_language_from I18n.available_locales
#
def compatible_language_from(available_languages)
- user_preferred_languages.map do |preferred|
+ user_preferred_languages.find do |preferred|
available_languages.find { |available| available.to_s == preferred.to_s } ||
available_languages.find { |available| available.to_s =~ /^#{Regexp.escape(preferred.to_s)}-/ }
- end.compact.first
+ end
end
# Returns a supplied list of available locals without any extra application info

0 comments on commit 6037739

Please sign in to comment.