Commits

encukou committed 9f1ea8c

Speed up POFile.merge

The merge method did a `find` for every message in the file, resulting
in O(n^2) performance. This got very slow for large files.

Improve the situation by creating a dict or set from the entries,
and replacing `find` by a cheap lookup.

Comments (0)

Files changed (1)

         ``refpot``
             object POFile, the reference catalog.
         """
+        # Store entries in dict/set for faster access
+        self_entries = dict((entry.msgid, entry) for entry in self)
+        refpot_msgids = set(entry.msgid for entry in refpot)
+        # Merge entries that are in the refpot
         for entry in refpot:
-            e = self.find(entry.msgid, include_obsolete_entries=True)
+            e = self_entries.get(entry.msgid)
             if e is None:
                 e = POEntry()
                 self.append(e)
             e.merge(entry)
         # ok, now we must "obsolete" entries that are not in the refpot anymore
         for entry in self:
-            if refpot.find(entry.msgid) is None:
+            if entry.msgid not in refpot_msgids:
                 entry.obsolete = True
 
 # }}}