Skip to content

Commit 7009af6

Browse files
author
Gerald Young
committed
Avoid performance hit from converting dict to text and back again/outline.py
1 parent c7f583b commit 7009af6

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

synfig-studio/plugins/lottie-exporter/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ PLUGIN_NAME = lottie-exporter
44

55
EXTRA_FILES = canvas.py \
66
misc.py \
7-
settings.py
7+
settings.py \
8+
dumb_store.py
89

910
plugindir = ${datadir}/synfig/plugins/$(PLUGIN_NAME)
1011
plugin_DATA = \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# pylint: disable=line-too-long
2+
"""
3+
Store a value and retrieve it later
4+
"""
5+
6+
def init():
7+
global store_dict
8+
store_dict = {}
9+
10+
global store_next_key
11+
store_next_key = int()
12+
13+
14+
def put(value):
15+
global store_next_key
16+
key = str(store_next_key)
17+
store_next_key += 1
18+
19+
global store_dict
20+
store_dict[key] = value
21+
return key
22+
23+
def get(key):
24+
global store_dict
25+
if key not in store_dict:
26+
return None
27+
return store_dict[key]

synfig-studio/plugins/lottie-exporter/lottie-exporter.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from canvas import gen_canvas
1717
from layers.driver import gen_layers
1818
import settings
19+
import dumb_store
1920

2021

2122
def write_to(filename, extension, data):
@@ -130,6 +131,7 @@ def init_logs():
130131
sys.exit()
131132
else:
132133
settings.init()
134+
dumb_store.init()
133135
FILE_NAME = sys.argv[1]
134136
new_file_name = parse(FILE_NAME)
135137
gen_html(new_file_name)

synfig-studio/plugins/lottie-exporter/properties/shapePropKeyframe/helper.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import sys
8-
import ast
8+
import dumb_store
99
from lxml import etree
1010
import settings
1111
from misc import change_axis, get_frame, Vector, is_animated, radial_to_tangent
@@ -28,7 +28,7 @@ def append_path(element, parent, element_name, typ="real"):
2828
gen_properties_multi_dimensional_keyframed(element_dict, element, 0)
2929
# Store in lxml element
3030
element_lxml = etree.Element(element_name)
31-
element_lxml.text = str(element_dict)
31+
element_lxml.text = dumb_store.put(element_dict)
3232
parent.append(element_lxml)
3333

3434

@@ -181,24 +181,24 @@ def get_tangent_at_frame(t1, t2, split_r, split_a, fr):
181181
# Setting tangent 1
182182
for chld in t1:
183183
if chld.tag == "radius_path":
184-
dictionary = ast.literal_eval(chld.text)
184+
dictionary = dumb_store.get(chld.text)
185185
r1 = get_vector_at_frame(dictionary, fr)
186186
elif chld.tag == "theta_path":
187-
dictionary = ast.literal_eval(chld.text)
187+
dictionary = dumb_store.get(chld.text)
188188
a1 = get_vector_at_frame(dictionary, fr)
189189
x, y = radial_to_tangent(r1, a1)
190190
tangent1 = Vector(x, y)
191191

192192
# Setting tangent 2
193193
for chld in t2:
194194
if chld.tag == "radius_path":
195-
dictionary = ast.literal_eval(chld.text)
195+
dictionary = dumb_store.get(chld.text)
196196
r2 = get_vector_at_frame(dictionary, fr)
197197
if not sp_r:
198198
# Use t1's radius
199199
r2 = r1
200200
elif chld.tag == "theta_path":
201-
dictionary = ast.literal_eval(chld.text)
201+
dictionary = dumb_store.get(chld.text)
202202
a2 = get_vector_at_frame(dictionary, fr)
203203
if not sp_a:
204204
# Use t1's angle

synfig-studio/plugins/lottie-exporter/properties/shapePropKeyframe/outline.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66

77
import sys
8-
import ast
98
import math
9+
import dumb_store
1010
import settings
1111
from misc import Vector, Hermite
1212
from synfig.animation import to_Synfig_axis, get_vector_at_frame, get_bool_at_frame, gen_dummy_waypoint
@@ -203,7 +203,7 @@ def get_outline_grow(fr):
203203
else:
204204
for chld in og:
205205
if chld.tag == "outline_grow_path":
206-
dictionary = ast.literal_eval(chld.text)
206+
dictionary = dumb_store.get(chld.text)
207207
val = to_Synfig_axis(get_vector_at_frame(dictionary, fr), "real")
208208
ret += val
209209
ret = math.e ** ret
@@ -229,10 +229,10 @@ def get_outline_param_at_frame(composite, fr):
229229
"""
230230
for child in composite:
231231
if child.tag == "point_path":
232-
dictionary = ast.literal_eval(child.text)
232+
dictionary = dumb_store.get(child.text)
233233
pos = get_vector_at_frame(dictionary, fr)
234234
elif child.tag == "width_path":
235-
dictionary = ast.literal_eval(child.text)
235+
dictionary = dumb_store.get(child.text)
236236
width = to_Synfig_axis(get_vector_at_frame(dictionary, fr), "real")
237237
elif child.tag == "t1":
238238
t1 = child[0]

synfig-studio/plugins/lottie-exporter/properties/shapePropKeyframe/polygon.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import sys
8-
import ast
8+
import dumb_store
99
from misc import Vector
1010
from synfig.animation import get_vector_at_frame, gen_dummy_waypoint
1111
from properties.multiDimensionalKeyframed import gen_properties_multi_dimensional_keyframed
@@ -82,7 +82,7 @@ def gen_dynamic_list_polygon(lottie, dynamic_list):
8282
# Only two childs, one should be animated, other one is path
8383
for child in entry:
8484
if child.tag == "pos_path":
85-
dictionary = ast.literal_eval(child.text)
85+
dictionary = dumb_store.get(child.text)
8686
pos_cur = get_vector_at_frame(dictionary, fr)
8787
pos_next = get_vector_at_frame(dictionary, nx_fr)
8888

synfig-studio/plugins/lottie-exporter/properties/shapePropKeyframe/region.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import sys
8-
import ast
8+
import dumb_store
99
from synfig.animation import get_vector_at_frame, gen_dummy_waypoint
1010
from properties.multiDimensionalKeyframed import gen_properties_multi_dimensional_keyframed
1111
from properties.shapePropKeyframe.helper import insert_dict_at, update_frame_window, update_child_at_parent, append_path, animate_radial_composite, get_tangent_at_frame, convert_tangent_to_lottie, update_frame_set, next_frame, trunc_decimals
@@ -115,7 +115,7 @@ def gen_bline_region(lottie, bline_point):
115115
composite = entry[0]
116116
for child in composite:
117117
if child.tag == "point_path":
118-
dictionary = ast.literal_eval(child.text)
118+
dictionary = dumb_store.get(child.text)
119119
pos_cur = get_vector_at_frame(dictionary, fr)
120120
pos_next = get_vector_at_frame(dictionary, nx_fr)
121121
elif child.tag == "t1":

0 commit comments

Comments
 (0)