changeset 4374:9edc2d6f7c10

dirstate: speed up write by 50%.
author Bryan O'Sullivan <bos@serpentine.com>
date Tue, 24 Apr 2007 12:02:42 -0700
parents abeb3edb2b4e
children 109077e7048d
files mercurial/dirstate.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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):