mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Added memoization optimization to tokenize function.
This commit is contained in:
parent
8fc200ae1f
commit
06cd9ae285
@ -263,6 +263,27 @@ class Tokenizer:
|
|||||||
args[-1].append(ends.pop())
|
args[-1].append(ends.pop())
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
_lastTokenized = None
|
||||||
|
_lastTokenizeResult = None
|
||||||
|
def tokenize(s):
|
||||||
|
"""A utility function to create a Tokenizer and tokenize a string."""
|
||||||
|
global _lastTokenized, _lastTokenizeResult
|
||||||
|
start = time.time()
|
||||||
|
try:
|
||||||
|
if s != _lastTokenized:
|
||||||
|
_lastTokenized = s
|
||||||
|
if conf.enablePipeSyntax:
|
||||||
|
tokens = '|'
|
||||||
|
else:
|
||||||
|
tokens = ''
|
||||||
|
_lastTokenizeResult = Tokenizer(tokens).tokenize(s)
|
||||||
|
except ValueError, e:
|
||||||
|
_lastTokenized = None
|
||||||
|
_lastTokenizedResult = None
|
||||||
|
raise SyntaxError, str(e)
|
||||||
|
debug.msg('tokenize took %s seconds.' % (time.time() - start), 'verbose')
|
||||||
|
return _lastTokenizeResult
|
||||||
|
|
||||||
def tokenize(s):
|
def tokenize(s):
|
||||||
"""A utility function to create a Tokenizer and tokenize a string."""
|
"""A utility function to create a Tokenizer and tokenize a string."""
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
Loading…
Reference in New Issue
Block a user