dirstate: speed up write by 50%.
authorBryan O'Sullivan <bos@serpentine.com>
Tue, 24 Apr 2007 12:02:42 -0700
changeset 4374 9edc2d6f7c10
parent 4373 abeb3edb2b4e
child 4375 109077e7048d
dirstate: speed up write by 50%.
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Tue Apr 24 11:46:15 2007 -0700
+++ b/mercurial/dirstate.py	Tue Apr 24 12:02:42 2007 -0700
@@ -10,6 +10,7 @@
 from node import *
 from i18n import _
 import struct, os, time, bisect, stat, strutil, util, re, errno
+import cStringIO
 
 class dirstate(object):
     format = ">cllll"
@@ -336,15 +337,17 @@
     def write(self):
         if not self.dirty:
             return
-        st = self.opener("dirstate", "w", atomictemp=True)
-        st.write("".join(self.pl))
-        for f, e in self.map.items():
+        cs = cStringIO.StringIO()
+        cs.write("".join(self.pl))
+        for f, e in self.map.iteritems():
             c = self.copied(f)
             if c:
                 f = f + "\0" + c
             e = struct.pack(self.format, e[0], e[1], e[2], e[3], len(f))
-            st.write(e + f)
-        st.rename()
+            cs.write(e)
+            cs.write(f)
+        st = self.opener("dirstate", "w", atomic=True)
+        st.write(cs.getvalue())
         self.dirty = 0
 
     def filterfiles(self, files):