From d6d4d60109af87889e57ee263f64d2f7955890c3 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 28 Jan 2012 01:50:14 +0000 Subject: [PATCH] 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 --- django/template/base.py | 7 ++++--- 1 file 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: