mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Avoided isinstance(…, Variable) calls in FilterExpression.resolve().
By determining the variable type within __init__() instead of resolve() we can skip an isinstance() check at template runtime. Templates are executed in production more often than the parse trees themselves, assuming the cached Loader is used.
This commit is contained in:
parent
c67e1cf44f
commit
96e7ff5e9f
@ -694,9 +694,10 @@ class FilterExpression:
|
||||
|
||||
self.filters = filters
|
||||
self.var = var_obj
|
||||
self.is_var = isinstance(var_obj, Variable)
|
||||
|
||||
def resolve(self, context, ignore_failures=False):
|
||||
if isinstance(self.var, Variable):
|
||||
if self.is_var:
|
||||
try:
|
||||
obj = self.var.resolve(context)
|
||||
except VariableDoesNotExist:
|
||||
|
@ -77,6 +77,7 @@ class TranslateNode(Node):
|
||||
self.message_context = message_context
|
||||
self.filter_expression = filter_expression
|
||||
if isinstance(self.filter_expression.var, str):
|
||||
self.filter_expression.is_var = True
|
||||
self.filter_expression.var = Variable("'%s'" %
|
||||
self.filter_expression.var)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user