From: Kevan Carstensen Date: Sat, 13 Aug 2011 18:38:33 +0000 (-0700) Subject: mutable/retrieve.py: use floor division to calculate segment boundaries, don't fetch... X-Git-Tag: trac-5200~1 X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=3423b7d6f78629a15fc4da9705e5e03469b48661;p=tahoe-lafs%2Ftahoe-lafs.git mutable/retrieve.py: use floor division to calculate segment boundaries, don't fetch more segments than necessary --- diff --git a/src/allmydata/mutable/retrieve.py b/src/allmydata/mutable/retrieve.py index d5f17111..cd67f836 100644 --- a/src/allmydata/mutable/retrieve.py +++ b/src/allmydata/mutable/retrieve.py @@ -385,11 +385,7 @@ class Retrieve: self.log("got offset: %d" % self._offset) # our start segment is the first segment containing the # offset we were given. - start = mathutil.div_ceil(self._offset, - self._segment_size) - # this gets us the first segment after self._offset. Then - # our start segment is the one before it. - start -= 1 + start = self._offset // self._segment_size assert start < self._num_segments self._start_segment = start @@ -403,9 +399,11 @@ class Retrieve: # segment that we were asked to read. self.log("got read length %d" % self._read_length) end_data = self._offset + self._read_length - end = mathutil.div_ceil(end_data, - self._segment_size) - end -= 1 + # We don't actually need to read the byte at end_data, but + # the one before it. + end_data = end_data - 1 + end = end_data // self._segment_size + assert end < self._num_segments self._last_segment = end self.log("got end segment: %d" % self._last_segment)