encukou  committed 1d0616c

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.

  • Participants
  • Parent commits 4dc072d
  • Branches default

Comments (0)

Files changed (1)

             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()
         # 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_entries:
                 entry.obsolete = True
 # }}}