GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added local assign keys to compiled method name so two threads evaluating 
the same template with different locals don't step on top of each other
josh (author)
Sat Jul 05 23:13:15 -0700 2008
commit  1d8623b42f6249613d39e834a8742b3b143f2aff
tree    f8316aab80fd86c15008d218d2a33717ff4b3c74
parent  7b9e8ae2734089555e5bfdb9e9c80d92f43551a2
...
12
13
14
15
 
16
17
18
...
28
29
30
 
 
 
 
 
 
31
32
...
12
13
14
 
15
16
17
18
...
28
29
30
31
32
33
34
35
36
37
38
0
@@ -12,7 +12,7 @@ module ActionView
0
     end
0
 
0
     def method
0
- ['_run', @extension, @method_segment].compact.join('_').to_sym
0
+ ['_run', @extension, @method_segment, local_assigns_keys].compact.join('_').to_sym
0
     end
0
 
0
     private
0
@@ -28,5 +28,11 @@ module ActionView
0
           @prepared = true
0
         end
0
       end
0
+
0
+ def local_assigns_keys
0
+ if @locals && @locals.any?
0
+ "locals_#{@locals.keys.map { |k| k.to_s }.sort.join('_')}"
0
+ end
0
+ end
0
   end
0
 end
...
20
21
22
23
 
24
25
26
...
20
21
22
 
23
24
25
26
0
@@ -20,7 +20,7 @@ module ActionView #:nodoc:
0
       set_extension_and_file_name
0
 
0
       @method_segment = compiled_method_name_file_path_segment
0
- @locals = locals || {}
0
+ @locals = (locals && locals.dup) || {}
0
       @handler = self.class.handler_class_for_extension(@extension).new(@view)
0
     end
0
 
...
5
6
7
8
9
10
11
12
13
...
26
27
28
29
30
31
32
33
 
34
35
36
...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
5
6
7
 
 
 
8
9
10
...
23
24
25
 
 
 
 
 
26
27
28
29
...
62
63
64
 
 
 
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
0
@@ -5,9 +5,6 @@ module ActionView
0
         base.extend ClassMethod
0
 
0
         @@mutex = Mutex.new
0
-
0
- # Map method names to the compiled local assigns
0
- @@template_args = {}
0
       end
0
 
0
       module ClassMethod
0
@@ -26,11 +23,7 @@ module ActionView
0
         return false unless recompile_template?(template)
0
 
0
         @@mutex.synchronize do
0
- locals_code = ""
0
- locals_keys = cache_template_args(template.method, template.locals)
0
- locals_keys.each do |key|
0
- locals_code << "#{key} = local_assigns[:#{key}];"
0
- end
0
+ locals_code = template.locals.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
0
 
0
           source = <<-end_src
0
             def #{template.method}(local_assigns)
0
@@ -69,25 +62,9 @@ module ActionView
0
           # Always recompile inline templates
0
           return true if template.is_a?(InlineTemplate)
0
 
0
- # Unless local assigns support, recompile
0
- return true unless supports_local_assigns?(template.method, template.locals)
0
-
0
           # Otherwise, use compiled method
0
           return false
0
         end
0
-
0
- def cache_template_args(render_symbol, local_assigns)
0
- @@template_args[render_symbol] ||= {}
0
- locals_keys = @@template_args[render_symbol].keys | local_assigns.keys
0
- @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
0
- locals_keys
0
- end
0
-
0
- # Return true if the given template was compiled for a superset of the keys in local_assigns
0
- def supports_local_assigns?(render_symbol, local_assigns)
0
- local_assigns.empty? ||
0
- ((args = @@template_args[render_symbol]) && local_assigns.all? { |k,_| args.has_key?(k) })
0
- end
0
     end
0
   end
0
 end

Comments

    No one has commented yet.