Permalink
Browse files

reuse the route collection and formatter by clearing them

  • Loading branch information...
1 parent 4ffe667 commit 59b9fe961d2195b35f3934dc6228a248897656e6 @tenderlove tenderlove committed Sep 8, 2011
Showing with 10 additions and 6 deletions.
  1. +10 −6 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -228,6 +228,13 @@ def initialize(request_class = ActionDispatch::Request)
@append = []
@prepend = []
@disable_clear_and_finalize = false
+
+ @set = Journey::Routes.new
+ @router = Journey::Router.new(@set, {
+ :parameters_key => PARAMETERS_KEY,
+ :request_class => request_class})
+ @formatter = Journey::Formatter.new @set
+
clear!
end
@@ -270,11 +277,8 @@ def clear!
@finalized = false
routes.clear
named_routes.clear
- @set = Journey::Routes.new
- @router = Journey::Router.new(@set, {
- :parameters_key => PARAMETERS_KEY,
- :request_class => request_class})
- @formatter = Journey::Formatter.new @set
+ set.clear
+ formatter.clear
@prepend.each { |blk| eval_block(blk) }
end
@@ -343,7 +347,7 @@ def empty?
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
route = Route.new(self, app, conditions, requirements, defaults, name, anchor)
- @set.add_route(route.app, route.conditions, route.defaults, route.name)
+ @set.add_route(app, route.conditions, defaults, name)
named_routes[name] = route if name
routes << route
route

0 comments on commit 59b9fe9

Please sign in to comment.