From c99ff6df0031a10d67d6185597085a6bcbeee114 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 20 May 2014 13:17:39 -0700 Subject: cache the formatter on the path object --- actionpack/lib/action_dispatch/journey/path/pattern.rb | 5 +++++ actionpack/lib/action_dispatch/journey/route.rb | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/journey/path/pattern.rb b/actionpack/lib/action_dispatch/journey/path/pattern.rb index fb155e516f..28c75618de 100644 --- a/actionpack/lib/action_dispatch/journey/path/pattern.rb +++ b/actionpack/lib/action_dispatch/journey/path/pattern.rb @@ -28,6 +28,11 @@ module ActionDispatch @required_names = nil @re = nil @offsets = nil + @format = Visitors::FormatBuilder.new.accept(spec) + end + + def format_path(path_options) + @format.evaluate path_options end def ast diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index 7535a62740..d4df96314f 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -76,8 +76,7 @@ module ActionDispatch value.to_s == defaults[key].to_s && !required_parts.include?(key) end - format = Visitors::FormatBuilder.new.accept(path.spec) - format.evaluate path_options + path.format_path path_options end def optimized_path -- cgit v1.2.3