Skip to content
This repository

RouteSet: remove some code dups #6138

Merged
merged 1 commit into from almost 2 years ago

2 participants

Bogdan Gusiev José Valim
Bogdan Gusiev
bogdan commented May 03, 2012

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)
José Valim josevalim merged commit 5c0cbb3 into from May 03, 2012
José Valim josevalim closed this May 03, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 02, 2012
Bogdan Gusiev RouteSet: remove some code dups da88d80
This page is out of date. Refresh to see the latest.
29  actionpack/lib/action_dispatch/routing/route_set.rb
@@ -184,27 +184,18 @@ def define_named_route_methods(name, route)
184 184
           def define_url_helper(route, name, options)
185 185
             selector = url_helper_name(name, options[:only_path])
186 186
 
187  
-            if optimize_helper?(route)
188  
-              @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
189  
-                remove_possible_method :#{selector}
190  
-                def #{selector}(*args)
191  
-                  if args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
192  
-                    options = #{options.inspect}.merge!(url_options)
193  
-                    options[:path] = "#{optimized_helper(route)}"
194  
-                    ActionDispatch::Http::URL.url_for(options)
195  
-                  else
196  
-                    url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
197  
-                  end
198  
-                end
199  
-              END_EVAL
200  
-            else
201  
-              @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
202  
-                remove_possible_method :#{selector}
203  
-                def #{selector}(*args)
  187
+            @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
  188
+              remove_possible_method :#{selector}
  189
+              def #{selector}(*args)
  190
+                if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
  191
+                  options = #{options.inspect}.merge!(url_options)
  192
+                  options[:path] = "#{optimized_helper(route)}"
  193
+                  ActionDispatch::Http::URL.url_for(options)
  194
+                else
204 195
                   url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
205 196
                 end
206  
-              END_EVAL
207  
-            end
  197
+              end
  198
+            END_EVAL
208 199
 
209 200
             helpers << selector
210 201
           end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.