Skip to content

Commit 4b2ebcb

Browse files
committed
Using lru_cache when available for definitions
- Since the new thing will do lookup and those instances should be initialized with a tuple, it should maintain a constant value that can be resolved through the cache.
1 parent 76cfb69 commit 4b2ebcb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/calmjs/parse/unparsers/walker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
from __future__ import unicode_literals
88

9+
try:
10+
from functools import lru_cache
11+
except ImportError: # pragma: no cover
12+
def lru_cache(*a, **kw):
13+
def wrapper(f):
14+
return f
15+
return wrapper
16+
917
from calmjs.parse.asttypes import Node
1018
from calmjs.parse.ruletypes import Token
1119
from calmjs.parse.ruletypes import Structure
@@ -147,6 +155,7 @@ def __init__(
147155

148156
self.__optimized_definitions = self.optimize()
149157

158+
@lru_cache(maxsize=None)
150159
def optimize_definition(self, name, definition):
151160
rules = []
152161
for rule in definition:

0 commit comments

Comments
 (0)