Rev 2326: For python 2.5, use a Struct object directly for stat packing. in http://bazaar.launchpad.net/~bzr/bzr/dirstate

Robert Collins robertc at robertcollins.net
Thu Mar 8 05:45:29 GMT 2007


At http://bazaar.launchpad.net/~bzr/bzr/dirstate

------------------------------------------------------------
revno: 2326
revision-id: robertc at robertcollins.net-20070308054243-tmrcsl7dqya6q7ta
parent: robertc at robertcollins.net-20070308023456-qlqjwtwuxvyggan0
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Thu 2007-03-08 16:42:43 +1100
message:
  For python 2.5, use a Struct object directly for stat packing.
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-03-08 02:34:56 +0000
+++ b/bzrlib/dirstate.py	2007-03-08 05:42:43 +0000
@@ -2283,17 +2283,32 @@
         else: hi = mid
     return lo
 
-
-
-def pack_stat(st, _b2a_base64=binascii.b2a_base64, _pack=struct.pack):
-    """Convert stat values into a packed representation."""
-    # jam 20060614 it isn't really worth removing more entries if we
-    # are going to leave it in packed form.
-    # With only st_mtime and st_mode filesize is 5.5M and read time is 275ms
-    # With all entries filesize is 5.9M and read time is mabye 280ms
-    # well within the noise margin
-
-    # base64.encode always adds a final newline, so strip it off
-    return _b2a_base64(_pack('>llllll'
-        , st.st_size, int(st.st_mtime), int(st.st_ctime)
-        , st.st_dev, st.st_ino, st.st_mode))[:-1]
+if not getattr(struct, '_compile', None):
+    def pack_stat(st, _b2a_base64=binascii.b2a_base64, _pack=struct.pack):
+        """Convert stat values into a packed representation."""
+        # jam 20060614 it isn't really worth removing more entries if we
+        # are going to leave it in packed form.
+        # With only st_mtime and st_mode filesize is 5.5M and read time is 275ms
+        # With all entries filesize is 5.9M and read time is mabye 280ms
+        # well within the noise margin
+
+        # base64.encode always adds a final newline, so strip it off
+        return _b2a_base64(_pack('>llllll'
+            , st.st_size, int(st.st_mtime), int(st.st_ctime)
+            , st.st_dev, st.st_ino, st.st_mode))[:-1]
+else:
+    # compile the struct compiler we need, because bytecode sucks.
+    from _struct import Struct
+    stat_packer = Struct('>llllll').pack
+    def pack_stat(st, _b2a_base64=binascii.b2a_base64, _pack=stat_packer):
+        """Convert stat values into a packed representation."""
+        # jam 20060614 it isn't really worth removing more entries if we
+        # are going to leave it in packed form.
+        # With only st_mtime and st_mode filesize is 5.5M and read time is 275ms
+        # With all entries filesize is 5.9M and read time is mabye 280ms
+        # well within the noise margin
+
+        # base64.encode always adds a final newline, so strip it off
+        return _b2a_base64(_pack(
+            st.st_size, int(st.st_mtime), int(st.st_ctime),
+            st.st_dev, st.st_ino, st.st_mode))[:-1]



More information about the bazaar-commits mailing list