summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2012-01-28 01:50:14 +0000
committerAdrian Holovaty <adrian@holovaty.com>2012-01-28 01:50:14 +0000
commitd6d4d60109af87889e57ee263f64d2f7955890c3 (patch)
tree28af0721e8b5ece8b8f6628c558ac3d49258ae8b
parent234b7e372000381657250fe133cbcfa90ffbb2a9 (diff)
Made a tiny performance improvement in the template system's Parser.parse() -- don't look up the global variables TOKEN_TEXT, etc.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17400 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/base.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 9472323853..e2fc66be01 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -237,15 +237,16 @@ class Parser(object):
nodelist = self.create_nodelist()
while self.tokens:
token = self.next_token()
- if token.token_type == TOKEN_TEXT:
+ # Use the raw values here for TOKEN_* for a tiny performance boost.
+ if token.token_type == 0: # TOKEN_TEXT
self.extend_nodelist(nodelist, TextNode(token.contents), token)
- elif token.token_type == TOKEN_VAR:
+ elif token.token_type == 1: # TOKEN_VAR
if not token.contents:
self.empty_variable(token)
filter_expression = self.compile_filter(token.contents)
var_node = self.create_variable_node(filter_expression)
self.extend_nodelist(nodelist, var_node, token)
- elif token.token_type == TOKEN_BLOCK:
+ elif token.token_type == 2: # TOKEN_BLOCK
try:
command = token.contents.split()[0]
except IndexError: