[symfont] Use dict.__missing__ trick for memoize
This commit is contained in:
parent
f13fbdae63
commit
087d865831
@ -117,20 +117,18 @@ class {name}(BasePen):
|
|||||||
# ('momentYY', y*y)])
|
# ('momentYY', y*y)])
|
||||||
|
|
||||||
|
|
||||||
class BezierFuncs(object):
|
class BezierFuncs(dict):
|
||||||
|
|
||||||
def __init__(self, symfunc):
|
def __init__(self, symfunc):
|
||||||
self._symfunc = symfunc
|
self._symfunc = symfunc
|
||||||
self._bezfuncs = {}
|
self._bezfuncs = {}
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __missing__(self, i):
|
||||||
if i not in self._bezfuncs:
|
|
||||||
args = []
|
args = []
|
||||||
for d in range(i+1):
|
for d in range(i+1):
|
||||||
args.append('x%d' % d)
|
args.append('x%d' % d)
|
||||||
args.append('y%d' % d)
|
args.append('y%d' % d)
|
||||||
self._bezfuncs[i] = sp.lambdify(args, green(self._symfunc, BezierCurve[i]))
|
return sp.lambdify(args, green(self._symfunc, BezierCurve[i]))
|
||||||
return self._bezfuncs[i]
|
|
||||||
|
|
||||||
def printCache(func, file=sys.stdout):
|
def printCache(func, file=sys.stdout):
|
||||||
funcstr = str(func)
|
funcstr = str(func)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user