optimize emscript indexize using python re
This commit is contained in:
Родитель
8547bf5788
Коммит
82dbac5060
|
@ -187,17 +187,14 @@ def emscript(infile, settings, outfile, libraries=[]):
|
||||||
|
|
||||||
# calculations on merged forwarded data
|
# calculations on merged forwarded data
|
||||||
forwarded_json['Functions']['indexedFunctions'] = {}
|
forwarded_json['Functions']['indexedFunctions'] = {}
|
||||||
index_reps = []
|
|
||||||
i = 2
|
i = 2
|
||||||
for indexed in indexed_functions:
|
for indexed in indexed_functions:
|
||||||
index_reps.append((indexed, i))
|
forwarded_json['Functions']['indexedFunctions'][indexed] = i # make sure not to modify this python object later - we use it in indexize
|
||||||
forwarded_json['Functions']['indexedFunctions'][indexed] = i
|
|
||||||
i += 2
|
i += 2
|
||||||
forwarded_json['Functions']['nextIndex'] = i
|
forwarded_json['Functions']['nextIndex'] = i
|
||||||
|
indexing = forwarded_json['Functions']['indexedFunctions']
|
||||||
def indexize(js):
|
def indexize(js):
|
||||||
for indexed, i in index_reps:
|
return re.sub(r'{{{ FI_([\w\d_$]+) }}}', lambda m: str(indexing[m.groups(0)[0]]), js)
|
||||||
js = js.replace('{{{ FI_' + indexed + ' }}}', str(i)) # TODO: optimize, do them all with a regexp replace?
|
|
||||||
return js
|
|
||||||
# forward
|
# forward
|
||||||
forwarded_data = json.dumps(forwarded_json)
|
forwarded_data = json.dumps(forwarded_json)
|
||||||
forwarded_file = temp_files.get('.2.json').name
|
forwarded_file = temp_files.get('.2.json').name
|
||||||
|
|
Загрузка…
Ссылка в новой задаче