Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Micro optimization for build_named_route_call in PolymorphicRoutes:

1. use map instead of inject
2. use [].join("_") instead of '<<'. It is a little bit faster for ruby 1.9.2 and x2 faster for ruby 1.8.7. http://gist.github.com/548143

[#5450 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 331234e0aba80cdaa87f57dffd71afdd7175a700 1 parent cc5a9c6
@yury yury authored josevalim committed
Showing with 10 additions and 10 deletions.
  1. +10 −10 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
View
20 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -148,29 +148,29 @@ def routing_type(options)
def build_named_route_call(records, inflection, options = {})
unless records.is_a?(Array)
record = extract_record(records)
- route = ''
+ route = []
else
record = records.pop
- route = records.inject("") do |string, parent|
+ route = records.map do |parent|
if parent.is_a?(Symbol) || parent.is_a?(String)
- string << "#{parent}_"
+ parent
else
- string << ActiveModel::Naming.plural(parent).singularize
- string << "_"
+ ActiveModel::Naming.plural(parent).singularize
end
end
end
if record.is_a?(Symbol) || record.is_a?(String)
- route << "#{record}_"
+ route << record
else
route << ActiveModel::Naming.plural(record)
- route = route.singularize if inflection == :singular
- route << "_"
- route << "index_" if ActiveModel::Naming.uncountable?(record) && inflection == :plural
+ route = [route.join("_").singularize] if inflection == :singular
+ route << "index" if ActiveModel::Naming.uncountable?(record) && inflection == :plural
end
- action_prefix(options) + route + routing_type(options).to_s
+ route << routing_type(options)
+
+ action_prefix(options) + route.join("_")
end
def extract_record(record_or_hash_or_array)
Please sign in to comment.
Something went wrong with that request. Please try again.