Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored January 28, 2012

Showing 1 changed file with 4 additions and 3 deletions. Show diff stats Hide diff stats

  1. 7  django/template/base.py
7  django/template/base.py
@@ -237,15 +237,16 @@ def parse(self, parse_until=None):
237 237
         nodelist = self.create_nodelist()
238 238
         while self.tokens:
239 239
             token = self.next_token()
240  
-            if token.token_type == TOKEN_TEXT:
  240
+            # Use the raw values here for TOKEN_* for a tiny performance boost.
  241
+            if token.token_type == 0: # TOKEN_TEXT
241 242
                 self.extend_nodelist(nodelist, TextNode(token.contents), token)
242  
-            elif token.token_type == TOKEN_VAR:
  243
+            elif token.token_type == 1: # TOKEN_VAR
243 244
                 if not token.contents:
244 245
                     self.empty_variable(token)
245 246
                 filter_expression = self.compile_filter(token.contents)
246 247
                 var_node = self.create_variable_node(filter_expression)
247 248
                 self.extend_nodelist(nodelist, var_node, token)
248  
-            elif token.token_type == TOKEN_BLOCK:
  249
+            elif token.token_type == 2: # TOKEN_BLOCK
249 250
                 try:
250 251
                     command = token.contents.split()[0]
251 252
                 except IndexError:

0 notes on commit d6d4d60

Please sign in to comment.
Something went wrong with that request. Please try again.