Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

RouteSet: remove some code dups #6138

Merged
merged 1 commit into from

2 participants

@bogdan

Remove some code dups.

Ensure no performance degrade (probably compiler optimization saved our souls):

https://gist.github.com/2584434


Running benchmark with current working tree
Checkout HEAD^
Running benchmark with HEAD^
Checkout to previous HEAD again

                    user     system      total        real
------------------------------------------------draw routes
After patch:    0.300000   0.010000   0.310000 (  0.310616)
Before patch:   0.300000   0.000000   0.300000 (  0.311043)

--------------------------------------simple URL generation
After patch:    0.010000   0.000000   0.010000 (  0.006107)
Before patch:   0.010000   0.000000   0.010000 (  0.006176)

-------------------------URL generation with params as hash
After patch:    0.080000   0.000000   0.080000 (  0.075196)
Before patch:   0.070000   0.010000   0.080000 (  0.075134)

-------------------------------URL generation with globbing
After patch:    0.070000   0.000000   0.070000 (  0.077017)
Before patch:   0.080000   0.000000   0.080000 (  0.077661)
@josevalim josevalim merged commit 5c0cbb3 into rails:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2012
  1. @bogdan
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 19 deletions.
  1. +10 −19 actionpack/lib/action_dispatch/routing/route_set.rb
View
29 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -184,27 +184,18 @@ def define_named_route_methods(name, route)
def define_url_helper(route, name, options)
selector = url_helper_name(name, options[:only_path])
- if optimize_helper?(route)
- @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
- remove_possible_method :#{selector}
- def #{selector}(*args)
- if args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
- options = #{options.inspect}.merge!(url_options)
- options[:path] = "#{optimized_helper(route)}"
- ActionDispatch::Http::URL.url_for(options)
- else
- url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
- end
- end
- END_EVAL
- else
- @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
- remove_possible_method :#{selector}
- def #{selector}(*args)
+ @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
+ remove_possible_method :#{selector}
+ def #{selector}(*args)
+ if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
+ options = #{options.inspect}.merge!(url_options)
+ options[:path] = "#{optimized_helper(route)}"
+ ActionDispatch::Http::URL.url_for(options)
+ else
url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end
- END_EVAL
- end
+ end
+ END_EVAL
helpers << selector
end
Something went wrong with that request. Please try again.