Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.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 | f78eadbb5769 |
children | 9e055cfdd620 |
line wrap: on
line diff
--- a/mercurial/patch.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/patch.py Wed May 20 00:52:46 2009 +0200 @@ -452,11 +452,11 @@ if not m: raise PatchError(_("bad hunk #%d") % self.number) self.starta, foo, self.lena, self.startb, foo2, self.lenb = m.groups() - if self.lena == None: + if self.lena is None: self.lena = 1 else: self.lena = int(self.lena) - if self.lenb == None: + if self.lenb is None: self.lenb = 1 else: self.lenb = int(self.lenb) @@ -479,7 +479,7 @@ raise PatchError(_("bad hunk #%d") % self.number) foo, self.starta, foo2, aend, foo3 = m.groups() self.starta = int(self.starta) - if aend == None: + if aend is None: aend = self.starta self.lena = int(aend) - self.starta if self.starta: @@ -511,7 +511,7 @@ raise PatchError(_("bad hunk #%d") % self.number) foo, self.startb, foo2, bend, foo3 = m.groups() self.startb = int(self.startb) - if bend == None: + if bend is None: bend = self.startb self.lenb = int(bend) - self.startb if self.startb: @@ -872,7 +872,7 @@ if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or ((context is not False) and x.startswith('***************')))): try: - if context == None and x.startswith('***************'): + if context is None and x.startswith('***************'): context = True gpatch = changed.get(bfile) create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'