Kaydet (Commit) 7b3fea40 authored tarafından Miklos Vajna's avatar Miklos Vajna

android: speed up mobile-config.py

Make it O(N) instead of O(N^2), where N is the number of children of the
root note.

3.596s -> 0.960s for main.xcd

Change-Id: I1b9904a377603cd57f84636c873ed2b752abd101
üst ffffc526
......@@ -57,21 +57,20 @@ if __name__ == '__main__':
total += len(ET.tostring(child))
saved = 0
restarted = True
to_remove = []
while restarted:
restarted = False
for child in root:
section = child.attrib['{http://openoffice.org/2001/registry}name']
package = child.attrib['{http://openoffice.org/2001/registry}package']
size = len(ET.tostring(child));
key = '%s/%s' % (package, section)
if key in main_xcd_discard:
root.remove(child)
print 'removed %s - saving %d' % (key, size)
saved = saved + size
restarted = True
break
for child in root:
section = child.attrib['{http://openoffice.org/2001/registry}name']
package = child.attrib['{http://openoffice.org/2001/registry}package']
size = len(ET.tostring(child));
key = '%s/%s' % (package, section)
if key in main_xcd_discard:
print 'removed %s - saving %d' % (key, size)
saved = saved + size
to_remove.append(child)
for child in to_remove:
root.remove(child)
print "saved %d of %d bytes: %2.f%%" % (saved, total, saved*100.0/total)
......@@ -82,3 +81,5 @@ if __name__ == '__main__':
root.set('xmlns:oor', 'http://openoffice.org/2001/registry')
tree.write(sys.argv[2], 'UTF-8', True)
# vim:set shiftwidth=4 softtabstop=4 expandtab:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment