Commit 69202ec2 authored by Andrew McCreight's avatar Andrew McCreight
Browse files

Bug 1443230 - Keep hashtable of interface indexes in xpt.py. r=glandium

A lot of time is spent during the final big XPT link determining what
the index is for each interface.  Changing this to use a map
eliminates about 2/3 of the running time. This patch reduces the run
time to a little under a second on my local OSX machine.

MozReview-Commit-ID: CH4OYXtT19q

--HG--
extra : rebase_source : 6d6f755c57dcbf20112768583948f851b8bf34bf
parent 5c88095f
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -102,6 +102,38 @@ def enum(*names):
    return Foo()


# List with constant time index() and contains() methods.
class IndexedList(object):
    def __init__(self, iterable):
        self._list = []
        self._index_map = {}
        for i in iterable:
            self.append(i)

    def sort(self):
        self._list.sort()
        self._index_map = {val: i for i, val in enumerate(self._list)}

    def append(self, val):
        self._index_map[val] = len(self._list)
        self._list.append(val)

    def index(self, what):
        return self._index_map[what]

    def __contains__(self, what):
        return what in self._index_map

    def __iter__(self):
        return iter(self._list)

    def __getitem__(self, index):
        return self._list[index]

    def __len__(self):
        return len(self._list)


# Descriptor types as described in the spec
class Type(object):
    """
@@ -1150,7 +1182,7 @@ class Typelib(object):

        """
        self.version = version
        self.interfaces = list(interfaces)
        self.interfaces = IndexedList(interfaces)
        self.annotations = list(annotations)
        self.filename = None