optimize emscript indexize using python re

This commit is contained in:
Alon Zakai 2012-11-06 17:15:28 -08:00
Родитель 8547bf5788
Коммит 82dbac5060
1 изменённых файлов: 3 добавлений и 6 удалений

Просмотреть файл

@ -187,17 +187,14 @@ def emscript(infile, settings, outfile, libraries=[]):
# calculations on merged forwarded data
forwarded_json['Functions']['indexedFunctions'] = {}
index_reps = []
i = 2
for indexed in indexed_functions:
index_reps.append((indexed, i))
forwarded_json['Functions']['indexedFunctions'][indexed] = i
forwarded_json['Functions']['indexedFunctions'][indexed] = i # make sure not to modify this python object later - we use it in indexize
i += 2
forwarded_json['Functions']['nextIndex'] = i
indexing = forwarded_json['Functions']['indexedFunctions']
def indexize(js):
for indexed, i in index_reps:
js = js.replace('{{{ FI_' + indexed + ' }}}', str(i)) # TODO: optimize, do them all with a regexp replace?
return js
return re.sub(r'{{{ FI_([\w\d_$]+) }}}', lambda m: str(indexing[m.groups(0)[0]]), js)
# forward
forwarded_data = json.dumps(forwarded_json)
forwarded_file = temp_files.get('.2.json').name