aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/rendering.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-11-06 14:11:37 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-11-06 14:11:37 -0800
commitc8b566d54da278a8e675115bcf2e9590f75f5eb5 (patch)
treecf8cfac420d2d6d7bb3157b8ebeefdf1b09e2dc0 /actionpack/lib/abstract_controller/rendering.rb
parent779cd6ec61d9ca362d05fd113bcc219ff38eaf6c (diff)
downloadrails-c8b566d54da278a8e675115bcf2e9590f75f5eb5.tar.gz
rails-c8b566d54da278a8e675115bcf2e9590f75f5eb5.tar.bz2
rails-c8b566d54da278a8e675115bcf2e9590f75f5eb5.zip
use a set and reject to avoid array allocations
Diffstat (limited to 'actionpack/lib/abstract_controller/rendering.rb')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index a60fe7c1c1..9d2199a7b1 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -55,7 +55,9 @@ module AbstractController
Mime::TEXT
end
- DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
+ require 'set'
+
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %w(
@_action_name @_response_body @_formats @_prefixes @_config
@_view_context_class @_view_renderer @_lookup_context
@_routes @_db_runtime
@@ -65,9 +67,10 @@ module AbstractController
# You can overwrite this configuration per controller.
# :api: public
def view_assigns
- variables = instance_variables
- variables -= protected_instance_variables
- variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
+ protected_vars = _protected_ivars
+ variables = instance_variables
+
+ variables.reject! { |s| protected_vars.include? s }
variables.each_with_object({}) { |name, hash|
hash[name.slice(1, name.length)] = instance_variable_get(name)
}
@@ -108,5 +111,9 @@ module AbstractController
_normalize_options(options)
options
end
+
+ def _protected_ivars # :nodoc:
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES + protected_instance_variables
+ end
end
end