Skip to content

Commit

Permalink
Fixed django#16971 - Made the parsing of javascript files by 'makemes…
Browse files Browse the repository at this point in the history
…sages' much faster. Thanks Antti Haapala for the implementation and Ned Batchelder for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16924 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
aaugustin committed Oct 4, 2011
1 parent f3304d3 commit 2a04473
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -222,6 +222,7 @@ answer newbie questions, and generally made Django that much better:
Janos Guljas
Thomas Güttler <hv@tbz-pariv.de>
Horst Gutmann <zerok@zerokspot.com>
Antti Haapala <antti@industrialwebandmagic.com>
Scot Hacker <shacker@birdhouse.org>
dAniel hAhler
hambaloney
Expand Down
30 changes: 18 additions & 12 deletions django/utils/jslex.py
Expand Up @@ -51,19 +51,25 @@ def lex(self, text):
Yields pairs (`name`, `tokentext`).
"""
while text:
eaten = 0
for match in self.regexes[self.state].finditer(text):
for name, toktext in match.groupdict().iteritems():
if toktext is not None:
tok = self.toks[name]
new_state = tok.next
eaten += len(toktext)
yield (tok.name, toktext)
if new_state:
self.state = new_state
end = len(text)
state = self.state
regexes = self.regexes
toks = self.toks
start = 0

while start < end:
for match in regexes[state].finditer(text, start):
name = match.lastgroup
tok = toks[name]
toktext = match.group(name)
start += len(toktext)
yield (tok.name, toktext)

if tok.next:
state = tok.next
break
text = text[eaten:]

self.state = state


class JsLexer(Lexer):
Expand Down

0 comments on commit 2a04473

Please sign in to comment.