Reuse view_context_class when possible
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 https://github.com/rails/rails/pull/40204) we should be doing the same for view context classes.
This commit is contained in:
parent
6fb54c00e4
commit
94643fde8f
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user