Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use a set and reject to avoid array allocations
  • Loading branch information
tenderlove committed Nov 6, 2013
1 parent 779cd6e commit c8b566d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions actionpack/lib/abstract_controller/rendering.rb
Expand Up @@ -55,7 +55,9 @@ def rendered_format
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
Expand All @@ -65,9 +67,10 @@ def rendered_format
# 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)
}
Expand Down Expand Up @@ -108,5 +111,9 @@ def _normalize_render(*args, &block)
_normalize_options(options)
options
end

def _protected_ivars # :nodoc:
DEFAULT_PROTECTED_INSTANCE_VARIABLES + protected_instance_variables
end
end
end

0 comments on commit c8b566d

Please sign in to comment.