Rev 3706: Compiled the pack stat struct encoder. in http://people.ubuntu.com/~robertc/baz2.0/readdir

Robert Collins robertc at robertcollins.net
Sat Sep 13 23:11:02 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/readdir

------------------------------------------------------------
revno: 3706
revision-id: robertc at robertcollins.net-20080913221050-9jk5c88t80w0300j
parent: robertc at robertcollins.net-20080913075905-4q1okaa2yntxxop2
committer: Robert Collins <robertc at robertcollins.net>
branch nick: update_entry
timestamp: Sun 2008-09-14 08:10:50 +1000
message:
  Compiled the pack stat struct encoder.
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2008-09-13 07:59:05 +0000
+++ b/bzrlib/dirstate.py	2008-09-13 22:10:50 +0000
@@ -222,7 +222,10 @@
     )
 
 
-def pack_stat(st, _encode=binascii.b2a_base64, _pack=struct.pack):
+# compile the struct compiler we need, so as to only do it once
+from _struct import Struct
+_compiled_pack = Struct('>LLLLLL').pack
+def pack_stat(st, _encode=binascii.b2a_base64, _pack=_compiled_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.
@@ -232,8 +235,7 @@
 
     # base64 encoding always adds a final newline, so strip it off
     # The current version
-    return _encode(_pack('>LLLLLL'
-        , st.st_size, int(st.st_mtime), int(st.st_ctime)
+    return _encode(_pack(st.st_size, int(st.st_mtime), int(st.st_ctime)
         , st.st_dev, st.st_ino & 0xFFFFFFFF, st.st_mode))[:-1]
     # This is 0.060s / 1.520s faster by not encoding as much information
     # return _encode(_pack('>LL', int(st.st_mtime), st.st_mode))[:-1]




More information about the bazaar-commits mailing list