Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made a small optimization to the template lexer. There's no need to c…

…alculate the len of VARIABLE_TAG_START, et al, each time we create a token.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 234b7e372000381657250fe133cbcfa90ffbb2a9 1 parent 1d54e3a
Adrian Holovaty authored January 27, 2012

Showing 1 changed file with 7 additions and 11 deletions. Show diff stats Hide diff stats

  1. 18  django/template/base.py
18  django/template/base.py
@@ -204,22 +204,18 @@ def create_token(self, token_string, in_tag):
204 204
         otherwise it should be treated as a literal string.
205 205
         """
206 206
         if in_tag:
  207
+            # The [2:-2] ranges below strip off *_TAG_START and *_TAG_END.
  208
+            # We could do len(BLOCK_TAG_START) to be more "correct", but we've
  209
+            # hard-coded the 2s here for performance. And it's not like
  210
+            # the TAG_START values are going to change anytime, anyway.
207 211
             if token_string.startswith(VARIABLE_TAG_START):
208  
-                token = Token(TOKEN_VAR,
209  
-                              token_string[
210  
-                                len(VARIABLE_TAG_START):-len(VARIABLE_TAG_END)
211  
-                              ].strip())
  212
+                token = Token(TOKEN_VAR, token_string[2:-2].strip())
212 213
             elif token_string.startswith(BLOCK_TAG_START):
213  
-                token = Token(TOKEN_BLOCK,
214  
-                              token_string[
215  
-                                len(BLOCK_TAG_START):-len(BLOCK_TAG_END)
216  
-                              ].strip())
  214
+                token = Token(TOKEN_BLOCK, token_string[2:-2].strip())
217 215
             elif token_string.startswith(COMMENT_TAG_START):
218 216
                 content = ''
219 217
                 if token_string.find(TRANSLATOR_COMMENT_MARK):
220  
-                    content = token_string[
221  
-                                len(COMMENT_TAG_START):-len(COMMENT_TAG_END)
222  
-                              ].strip()
  218
+                    content = token_string[2:-2].strip()
223 219
                 token = Token(TOKEN_COMMENT, content)
224 220
         else:
225 221
             token = Token(TOKEN_TEXT, token_string)

0 notes on commit 234b7e3

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