summaryrefslogtreecommitdiff
path: root/django/template
diff options
context:
space:
mode:
authorKeryn Knight <keryn@kerynknight.com>2022-01-07 09:29:22 +0000
committerGitHub <noreply@github.com>2022-01-07 10:29:22 +0100
commit96e7ff5e9ff6362d9a886545869ce4496ca4b0fb (patch)
tree8dea06c48247e78ba0463045004ce62e9895e82a /django/template
parentc67e1cf44f17c36139e25b1eae92216cb8baad77 (diff)
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.
Diffstat (limited to 'django/template')
-rw-r--r--django/template/base.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 0dec9940ab..078be8b383 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -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: