Skip to content

Commit

Permalink
Reuse view_context_class when possible
Browse files Browse the repository at this point in the history
The generated view context classes tend to be fairly complex and use a
lot of memory. Similar to how we only generate new helper classes when
necessary (see #40204) we should be
doing the same for view context classes.
  • Loading branch information
jhawthorn committed Jan 6, 2022
1 parent 6fb54c0 commit 94643fd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions actionview/lib/action_view/rendering.rb
Expand Up @@ -48,7 +48,18 @@ def _routes
def _helpers
end

def inherit_view_context_class?
superclass.respond_to?(:view_context_class) &&
supports_path? == superclass.supports_path? &&
_routes.equal?(superclass._routes) &&
_helpers.equal?(superclass._helpers)
end

def build_view_context_class(klass, supports_path, routes, helpers)
if inherit_view_context_class?
return superclass.view_context_class
end

Class.new(klass) do
if routes
include routes.url_helpers(supports_path)
Expand Down

0 comments on commit 94643fd

Please sign in to comment.