obscache: directly allocate zeroed bytearray
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 09 Jun 2017 01:39:42 +0100
changeset 2570 86959f2c625d
parent 2569 427f6091250e
child 2571 3f469be5f3a7
obscache: directly allocate zeroed bytearray This is much faster that incrementally appending to it. On mozilla central without obsolescence markers this move full cache building from 0.3s to nothing visible.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Fri Jun 09 01:26:29 2017 +0100
+++ b/hgext3rd/evolve/obscache.py	Fri Jun 09 01:39:42 2017 +0100
@@ -417,16 +417,18 @@
         For now we stick to the simpler approach of paying the
         performance cost on new changesets.
         """
-        node = repo.changelog.node
-        succs = repo.obsstore.successors
-        for r in revs:
-            if node(r) in succs:
-                val = 1
-            else:
-                val = 0
-            self._data.append(val)
-        cl = repo.changelog
-        assert len(self._data) == len(cl), (len(self._data), len(cl))
+        new_entries = bytearray(len(revs))
+        if not self._data:
+            self._setdata(new_entries)
+        else:
+            self._data.extend(new_entries)
+        data = self._data
+        if repo.obsstore:
+            node = repo.changelog.node
+            succs = repo.obsstore.successors
+            for r in revs:
+                if node(r) in succs:
+                    data[r] = 1
 
     def _updatemarkers(self, repo, obsmarkers):
         """update the cache with new markers"""