Rev 2329: Tune the pack_stat step to not go through as many layers of indirection when possible. in file:///home/robertc/source/baz/dirstate2/
Robert Collins
robertc at robertcollins.net
Fri Mar 9 21:32:02 GMT 2007
At file:///home/robertc/source/baz/dirstate2/
------------------------------------------------------------
revno: 2329
revision-id: robertc at robertcollins.net-20070309213148-mmgmddc0a2yheitu
parent: robertc at robertcollins.net-20070309155213-fciselcj7bjb6swy
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate2
timestamp: Sat 2007-03-10 08:31:48 +1100
message:
Tune the pack_stat step to not go through as many layers of indirection when possible.
modified:
bzrlib/path_info_python.py path_info_python.py-20070309041626-f8val8ukxzzzyudi-2
=== modified file 'bzrlib/path_info_python.py'
--- a/bzrlib/path_info_python.py 2007-03-09 14:30:19 +0000
+++ b/bzrlib/path_info_python.py 2007-03-09 21:31:48 +0000
@@ -21,7 +21,7 @@
__all__ = ['pack_stat', 'path_info']
-import base64
+import binascii
import errno
import os
import stat
@@ -35,19 +35,24 @@
kind_file = sys.modules['bzrlib.path_info'].kind_file
-def pack_stat(st, _encode=base64.encodestring, _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 _encode(_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."""
+ # 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."""
+ # 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]
+
def path_info(abspath, _lstat=os.lstat, _mapper=file_kind_from_stat_mode,
_S_IEXEC=stat.S_IEXEC, _ENOENT=errno.ENOENT, _kind_missing=kind_missing,
More information about the bazaar-commits
mailing list