From 167742c2b3d477a66bed8b7e852308bda88ffca1 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 9 Jan 2009 19:52:22 -0700 Subject: [PATCH] storage.py : replace 4294967295 with 2**32-1: python does constant folding, I measured this statement as taking 50ns, versus the 400ns for the call to min(), or the 9us required for the 'assert not os.path.exists' syscall --- src/allmydata/storage.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/allmydata/storage.py b/src/allmydata/storage.py index f1ce2ece..0a15a123 100644 --- a/src/allmydata/storage.py +++ b/src/allmydata/storage.py @@ -112,15 +112,16 @@ class ShareFile: assert not os.path.exists(self.home) fileutil.make_dirs(os.path.dirname(self.home)) f = open(self.home, 'wb') - # The second field -- share data length -- is no longer used as of Tahoe v1.3.0, but - # we continue to write it in there in case someone downgrades a storage server from - # >= Tahoe-1.3.0 to < Tahoe-1.3.0, or moves a share file from one server to another, - # etc. We do saturation -- a share data length larger than what can fit into the - # field is marked as the largest length that can fit into the field. That way, even - # if this does happen, the old < v1.3.0 server will still allow clients to read the - # first part of the share. The largest size that will fit in this 4-byte field is - # 2**32-1, or 4294967295. - f.write(struct.pack(">LLL", 1, min(4294967295, max_size), 0)) + # The second field -- the four-byte share data length -- is no + # longer used as of Tahoe v1.3.0, but we continue to write it in + # there in case someone downgrades a storage server from >= + # Tahoe-1.3.0 to < Tahoe-1.3.0, or moves a share file from one + # server to another, etc. We do saturation -- a share data length + # larger than 2**32-1 (what can fit into the field) is marked as + # the largest length that can fit into the field. That way, even + # if this does happen, the old < v1.3.0 server will still allow + # clients to read the first part of the share. + f.write(struct.pack(">LLL", 1, min(2**32-1, max_size), 0)) f.close() self._lease_offset = max_size + 0x0c self._num_leases = 0 -- 2.45.2