diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-07 14:25:25 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-07 14:25:25 -0800 |
commit | 8b9e832213215111e221880259154cdd255f052e (patch) | |
tree | db288952bcdf35b2f9b7fd7c8154a95a1afd84bf | |
parent | bda9400d094292be27f4be43473b0d1fc656df32 (diff) |
more work on hackish function removal using profiling
-rw-r--r-- | tools/profile_stripper.py | 24 | ||||
-rw-r--r-- | tools/profile_used.py | 11 |
2 files changed, 23 insertions, 12 deletions
diff --git a/tools/profile_stripper.py b/tools/profile_stripper.py index bbc23937..3e538ef3 100644 --- a/tools/profile_stripper.py +++ b/tools/profile_stripper.py @@ -7,15 +7,37 @@ import sys, json used = json.loads(open(sys.argv[1]).read()) show = True +in_table = False for orig in open(sys.argv[2]).readlines(): line = orig.strip() + if orig.startswith('function _') and line.endswith(('){', ') {')): name = line.split(' ')[1].split('(')[0] if name.startswith('_') and not used.get(name): #print >> sys.stderr, 'remove', name show = False - if show: print orig, + + if line.startswith('var FUNCTION_TABLE'): + in_table = True + + if in_table: + start = 0 + if 'var ' in line: + start = line.index('[')+1 + end = len(line) + if ']' in line: + end = line.index(']') + contents = line[start:end] + fixed = map(lambda name: '"' + name + '"' if not used.get(name) else name, contents.split(',')) + print (line[:start] + ','.join(fixed) + line[end:]).replace('""', '') + else: + if show: + print orig, + if orig.startswith('}'): show = True + if in_table and line.endswith(';'): + in_table = False + diff --git a/tools/profile_used.py b/tools/profile_used.py index b954f7d1..45420e0f 100644 --- a/tools/profile_used.py +++ b/tools/profile_used.py @@ -7,10 +7,6 @@ dump(JSON.stringify(usedFunctions)) import sys print 'var usedFunctions = {};' -#print "function getFuncName(f) { return f.toString().split(' ')[1].split('(')[0] }" -print "function getFuncName(f) { return f.name }" - -last = [] for line in open(sys.argv[1]).readlines(): line = line.strip() @@ -18,11 +14,4 @@ for line in open(sys.argv[1]).readlines(): if line.startswith('function _') and line.endswith(('){', ') {')): name = line.split(' ')[1].split('(')[0] print 'usedFunctions["%s"] = 1;' % name - if line.startswith('var FUNCTION_TABLE'): - name = line.split(' ')[1].split('=')[0] - last += ['for (var i = 0; i < %s.length; i++) if (typeof %s[i] === "function") usedFunctions[getFuncName(%s[i])] = 1;' % (name, name, name)] - if len(last) > 0 and line.endswith(';'): - for l in last: - print l - last = [] |