comparison mercurial/revlog.py @ 8527:f9a80054dd3c

use 'x is None' instead of 'x == None' The built-in None object is a singleton and it is therefore safe to compare memory addresses with is. It is also faster, how much depends on the object being compared. For a simple type like str I get: | s = "foo" | s = None ----------+-----------+---------- s == None | 0.25 usec | 0.21 usec s is None | 0.17 usec | 0.17 usec
author Martin Geisler <mg@lazybytes.net>
date Wed, 20 May 2009 00:52:46 +0200
parents 7af92e70bb25
children 5726bb290bfe
comparison
equal deleted inserted replaced
8526:f78eadbb5769 8527:f9a80054dd3c
173 off = 0 173 off = 0
174 # lazyindex supports __delitem__ 174 # lazyindex supports __delitem__
175 if lend > len(self.index) - i: 175 if lend > len(self.index) - i:
176 lend = len(self.index) - i 176 lend = len(self.index) - i
177 for x in xrange(lend): 177 for x in xrange(lend):
178 if self.index[i + x] == None: 178 if self.index[i + x] is None:
179 b = data[off : off + self.s] 179 b = data[off : off + self.s]
180 self.index[i + x] = b 180 self.index[i + x] = b
181 n = b[ngshaoffset:ngshaoffset + 20] 181 n = b[ngshaoffset:ngshaoffset + 20]
182 self.map[n] = i + x 182 self.map[n] = i + x
183 off += self.s 183 off += self.s
229 229
230 def loadindex(self, i=None, end=None): 230 def loadindex(self, i=None, end=None):
231 if self.all: 231 if self.all:
232 return 232 return
233 all = False 233 all = False
234 if i == None: 234 if i is None:
235 blockstart = 0 235 blockstart = 0
236 blocksize = (65536 / self.s) * self.s 236 blocksize = (65536 / self.s) * self.s
237 end = self.datasize 237 end = self.datasize
238 all = True 238 all = True
239 else: 239 else:
277 """a lazy version of the node map""" 277 """a lazy version of the node map"""
278 def __init__(self, parser): 278 def __init__(self, parser):
279 self.p = parser 279 self.p = parser
280 def load(self, key): 280 def load(self, key):
281 n = self.p.findnode(key) 281 n = self.p.findnode(key)
282 if n == None: 282 if n is None:
283 raise KeyError(key) 283 raise KeyError(key)
284 def __contains__(self, key): 284 def __contains__(self, key):
285 if key in self.p.map: 285 if key in self.p.map:
286 return True 286 return True
287 self.p.loadmap() 287 self.p.loadmap()
1017 def checkinlinesize(self, tr, fp=None): 1017 def checkinlinesize(self, tr, fp=None):
1018 if not self._inline or (self.start(-2) + self.length(-2)) < 131072: 1018 if not self._inline or (self.start(-2) + self.length(-2)) < 131072:
1019 return 1019 return
1020 1020
1021 trinfo = tr.find(self.indexfile) 1021 trinfo = tr.find(self.indexfile)
1022 if trinfo == None: 1022 if trinfo is None:
1023 raise RevlogError(_("%s not found in the transaction") 1023 raise RevlogError(_("%s not found in the transaction")
1024 % self.indexfile) 1024 % self.indexfile)
1025 1025
1026 trindex = trinfo[2] 1026 trindex = trinfo[2]
1027 dataoff = self.start(trindex) 1027 dataoff = self.start(trindex)