mirror of
https://github.com/stevenrobertson/cuburn.git
synced 2025-02-05 11:40:04 -05:00
Precompile accessors.
This improves packing speed by 8x, which is visible on small or low-quality frames.
This commit is contained in:
parent
a12714f4c4
commit
d409f02e4a
@ -230,11 +230,12 @@ class DataPacker(HunkOCode):
|
|||||||
|
|
||||||
def _access(self, view, accessor, name):
|
def _access(self, view, accessor, name):
|
||||||
if name in self.packed:
|
if name in self.packed:
|
||||||
pview, paccessor = self.packed[name]
|
pview, paccessor, pcomp = self.packed[name]
|
||||||
if pview == view and (accessor is None or paccessor == accessor):
|
if pview == view and (accessor is None or paccessor == accessor):
|
||||||
return
|
return
|
||||||
raise ValueError("Same name, different accessor or view: %s" % name)
|
raise ValueError("Same name, different accessor or view: %s" % name)
|
||||||
self.packed[name] = (view, accessor)
|
comp_accessor = compile(accessor, '{{template}}', 'eval')
|
||||||
|
self.packed[name] = (view, accessor, comp_accessor)
|
||||||
self.packed_order.append(name)
|
self.packed_order.append(name)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
@ -251,11 +252,11 @@ class DataPacker(HunkOCode):
|
|||||||
subbed_nses = {}
|
subbed_nses = {}
|
||||||
|
|
||||||
for i, name in enumerate(self.packed_order):
|
for i, name in enumerate(self.packed_order):
|
||||||
view, accessor = self.packed[name]
|
view, accessor, comp = self.packed[name]
|
||||||
if view not in subbed_nses:
|
if view not in subbed_nses:
|
||||||
subbed_nses[view] = view._apply_subs(dict(base_ns))
|
subbed_nses[view] = view._apply_subs(dict(base_ns))
|
||||||
try:
|
try:
|
||||||
val = eval(accessor, subbed_nses[view])
|
val = eval(comp, subbed_nses[view])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print 'Error while evaluating accessor "%s"' % accessor
|
print 'Error while evaluating accessor "%s"' % accessor
|
||||||
raise e
|
raise e
|
||||||
|
Loading…
Reference in New Issue
Block a user