public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Remove some Symbol#to_proc usage in runtime code.  [#484 state:resolved]
chuyeow (author)
Wed Jun 25 19:21:53 -0700 2008
jeremy (committer)
Wed Jul 09 10:42:30 -0700 2008
commit  ce4a1bb8538bd7cc5ee3cbf1156dc587482a7839
tree    0730d2ed46c4dd77b5ed141d37e9e41952b5c68b
parent  11252e35b1756b025d8778c151f9f9a24057d1b1
...
412
413
414
415
 
416
417
418
...
420
421
422
423
 
424
425
426
427
428
 
 
 
429
430
431
...
1201
1202
1203
1204
 
1205
1206
1207
...
412
413
414
 
415
416
417
418
...
420
421
422
 
423
424
425
 
 
 
426
427
428
429
430
431
...
1201
1202
1203
 
1204
1205
1206
1207
0
@@ -412,7 +412,7 @@ module ActionController #:nodoc:
0
       # More methods can be hidden using <tt>hide_actions</tt>.
0
       def hidden_actions
0
         unless read_inheritable_attribute(:hidden_actions)
0
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(&:to_s))
0
+ write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map { |m| m.to_s })
0
         end
0
 
0
         read_inheritable_attribute(:hidden_actions)
0
@@ -420,12 +420,12 @@ module ActionController #:nodoc:
0
 
0
       # Hide each of the given methods from being callable as actions.
0
       def hide_action(*names)
0
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s))
0
+ write_inheritable_attribute(:hidden_actions, hidden_actions | names.map { |name| name.to_s })
0
       end
0
 
0
- ## View load paths determine the bases from which template references can be made. So a call to
0
- ## render("test/template") will be looked up in the view load paths array and the closest match will be
0
- ## returned.
0
+ # View load paths determine the bases from which template references can be made. So a call to
0
+ # render("test/template") will be looked up in the view load paths array and the closest match will be
0
+ # returned.
0
       def view_paths
0
         @view_paths || superclass.view_paths
0
       end
0
@@ -1201,7 +1201,7 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def self.action_methods
0
- @action_methods ||= Set.new(public_instance_methods.map(&:to_s)) - hidden_actions
0
+ @action_methods ||= Set.new(public_instance_methods.map { |m| m.to_s }) - hidden_actions
0
       end
0
 
0
       def add_variables_to_assigns
...
127
128
129
130
 
131
132
 
133
134
135
...
544
545
546
547
 
 
 
 
 
548
549
550
551
552
553
 
 
 
 
 
554
555
556
...
127
128
129
 
130
131
 
132
133
134
135
...
544
545
546
 
547
548
549
550
551
552
553
554
555
556
 
557
558
559
560
561
562
563
564
0
@@ -127,9 +127,9 @@ module ActionController #:nodoc:
0
 
0
         def included_in_action?(controller, options)
0
           if options[:only]
0
- Array(options[:only]).map(&:to_s).include?(controller.action_name)
0
+ Array(options[:only]).map { |o| o.to_s }.include?(controller.action_name)
0
           elsif options[:except]
0
- !Array(options[:except]).map(&:to_s).include?(controller.action_name)
0
+ !Array(options[:except]).map { |o| o.to_s }.include?(controller.action_name)
0
           else
0
             true
0
           end
0
@@ -544,13 +544,21 @@ module ActionController #:nodoc:
0
       # Returns all the before filters for this class and all its ancestors.
0
       # This method returns the actual filter that was assigned in the controller to maintain existing functionality.
0
       def before_filters #:nodoc:
0
- filter_chain.select(&:before?).map(&:method)
1
+ filters = []
0
+ filter_chain.each do |filter|
0
+ filters << filter.method if filter.before?
0
+ end
0
+ filters
0
       end
0
 
0
       # Returns all the after filters for this class and all its ancestors.
0
       # This method returns the actual filter that was assigned in the controller to maintain existing functionality.
0
       def after_filters #:nodoc:
0
- filter_chain.select(&:after?).map(&:method)
0
+ filters = []
0
+ filter_chain.each do |filter|
0
+ filters << filter.method if filter.after?
0
+ end
0
+ filters
0
       end
0
     end
0
 
...
1145
1146
1147
1148
 
1149
1150
1151
...
1490
1491
1492
1493
 
1494
1495
1496
...
1145
1146
1147
 
1148
1149
1150
1151
...
1490
1491
1492
 
1493
1494
1495
1496
0
@@ -1145,7 +1145,7 @@ module ActiveRecord
0
           end
0
 
0
           define_method("#{reflection.name.to_s.singularize}_ids") do
0
- send(reflection.name).map(&:id)
0
+ send(reflection.name).map { |record| record.id }
0
           end
0
         end
0
 
0
@@ -1490,7 +1490,7 @@ module ActiveRecord
0
           sql << " FROM #{connection.quote_table_name table_name} "
0
 
0
           if is_distinct
0
- sql << distinct_join_associations.collect(&:association_join).join
0
+ sql << distinct_join_associations.collect { |assoc| assoc.association_join }.join
0
             add_joins!(sql, options, scope)
0
           end
0
 
...
14
15
16
17
 
18
19
20
...
14
15
16
 
17
18
19
20
0
@@ -14,7 +14,7 @@ module ActiveRecord
0
         # If using a custom finder_sql, scan the entire collection.
0
         if @reflection.options[:finder_sql]
0
           expects_array = args.first.kind_of?(Array)
0
- ids = args.flatten.compact.uniq.map(&:to_i)
0
+ ids = args.flatten.compact.uniq.map { |arg| arg.to_i }
0
 
0
           if ids.size == 1
0
             id = ids.first
...
61
62
63
64
 
65
66
 
67
68
69
...
61
62
63
 
64
65
 
66
67
68
69
0
@@ -61,9 +61,9 @@ module ActiveRecord
0
         def delete_records(records)
0
           case @reflection.options[:dependent]
0
             when :destroy
0
- records.each(&:destroy)
0
+ records.each { |r| r.destroy }
0
             when :delete_all
0
- @reflection.klass.delete(records.map(&:id))
0
+ @reflection.klass.delete(records.map { |record| record.id })
0
             else
0
               ids = quoted_record_ids(records)
0
               @reflection.klass.update_all(
...
70
71
72
73
 
74
75
...
70
71
72
 
73
74
75
0
@@ -70,6 +70,6 @@ class Module
0
   # Returns the names of the constants defined locally rather than the
0
   # constants themselves. See <tt>local_constants</tt>.
0
   def local_constant_names
0
- local_constants.map(&:to_s)
0
+ local_constants.map { |c| c.to_s }
0
   end
0
 end
...
35
36
37
38
 
39
40
41
...
35
36
37
 
38
39
40
41
0
@@ -35,7 +35,7 @@ class Object
0
   # C.new(0, 1).instance_variable_names # => ["@y", "@x"]
0
   if RUBY_VERSION >= '1.9'
0
     def instance_variable_names
0
- instance_variables.map(&:to_s)
0
+ instance_variables.map { |var| var.to_s }
0
     end
0
   else
0
     alias_method :instance_variable_names, :instance_variables
...
387
388
389
390
 
391
392
393
...
437
438
439
440
 
441
442
443
...
387
388
389
 
390
391
392
393
...
437
438
439
 
440
441
442
443
0
@@ -387,7 +387,7 @@ module ActiveSupport #:nodoc:
0
     ensure
0
       # Remove the stack frames that we added.
0
       if defined?(watch_frames) && ! watch_frames.blank?
0
- frame_ids = watch_frames.collect(&:object_id)
0
+ frame_ids = watch_frames.collect { |frame| frame.object_id }
0
         constant_watch_stack.delete_if do |watch_frame|
0
           frame_ids.include? watch_frame.object_id
0
         end
0
@@ -437,7 +437,7 @@ module ActiveSupport #:nodoc:
0
     protected
0
       def log_call(*args)
0
         if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity
0
- arg_str = args.collect(&:inspect) * ', '
0
+ arg_str = args.collect { |arg| arg.inspect } * ', '
0
           /in `([a-z_\?\!]+)'/ =~ caller(1).first
0
           selector = $1 || '<unknown>'
0
           log "called #{selector}(#{arg_str})"

Comments

  • tsaleh Wed Jul 09 11:38:23 -0700 2008 at actionpack/lib/action_controller/filters.rb L143

    The speed increase here can’t possibly be worth the lack of readability.

  • jherdman Wed Jul 09 12:21:09 -0700 2008 at actionpack/lib/action_controller/filters.rb

    wouldn’t inject be more succinct? e.g.

    
    
    filter_chain.inject(Array.new) do |filters, filter_item|
    filters &lt;&lt; filter_item if filter_item.before?
    filters
    end

  • Aupajo Wed Jul 09 16:04:46 -0700 2008

    Believe it or not, those calls are sped up significantly :)
    See:
    http://blog.hasmanythrough.com/2006/3/7/symbol-to-proc-shorthand

  • michaelklishin Wed Jul 09 17:47:00 -0700 2008

    Go for it.

  • masterkain Thu Jul 10 16:00:02 -0700 2008


    user system total real
    Using Symbol#to_proc 2.860000 0.760000 3.620000 ( 3.702233)
    Standard call 2.740000 1.050000 3.790000 ( 3.867797)

  • evan Fri Jul 11 09:46:53 -0700 2008

    None of these appear to be in inner loops. What am I my missing?

  • NZKoz Sat Jul 12 01:40:56 -0700 2008

    The best way to raise questions about this changeset is to either email jeremy and chuyeow and ask, or to ask on the core list.

    Me, I have no idea either ;)