Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made a tiny performance improvement in the template system's Parser.p…

…arse() -- 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
  • Loading branch information...
commit d6d4d60109af87889e57ee263f64d2f7955890c3 1 parent 234b7e3
@adrianholovaty adrianholovaty authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 django/template/base.py
View
7 django/template/base.py
@@ -237,15 +237,16 @@ def parse(self, parse_until=None):
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:
Please sign in to comment.
Something went wrong with that request. Please try again.