comparison 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
comparison
equal deleted inserted replaced
8526:f78eadbb5769 8527:f9a80054dd3c
450 def read_unified_hunk(self, lr): 450 def read_unified_hunk(self, lr):
451 m = unidesc.match(self.desc) 451 m = unidesc.match(self.desc)
452 if not m: 452 if not m:
453 raise PatchError(_("bad hunk #%d") % self.number) 453 raise PatchError(_("bad hunk #%d") % self.number)
454 self.starta, foo, self.lena, self.startb, foo2, self.lenb = m.groups() 454 self.starta, foo, self.lena, self.startb, foo2, self.lenb = m.groups()
455 if self.lena == None: 455 if self.lena is None:
456 self.lena = 1 456 self.lena = 1
457 else: 457 else:
458 self.lena = int(self.lena) 458 self.lena = int(self.lena)
459 if self.lenb == None: 459 if self.lenb is None:
460 self.lenb = 1 460 self.lenb = 1
461 else: 461 else:
462 self.lenb = int(self.lenb) 462 self.lenb = int(self.lenb)
463 self.starta = int(self.starta) 463 self.starta = int(self.starta)
464 self.startb = int(self.startb) 464 self.startb = int(self.startb)
477 m = contextdesc.match(self.desc) 477 m = contextdesc.match(self.desc)
478 if not m: 478 if not m:
479 raise PatchError(_("bad hunk #%d") % self.number) 479 raise PatchError(_("bad hunk #%d") % self.number)
480 foo, self.starta, foo2, aend, foo3 = m.groups() 480 foo, self.starta, foo2, aend, foo3 = m.groups()
481 self.starta = int(self.starta) 481 self.starta = int(self.starta)
482 if aend == None: 482 if aend is None:
483 aend = self.starta 483 aend = self.starta
484 self.lena = int(aend) - self.starta 484 self.lena = int(aend) - self.starta
485 if self.starta: 485 if self.starta:
486 self.lena += 1 486 self.lena += 1
487 for x in xrange(self.lena): 487 for x in xrange(self.lena):
509 m = contextdesc.match(l) 509 m = contextdesc.match(l)
510 if not m: 510 if not m:
511 raise PatchError(_("bad hunk #%d") % self.number) 511 raise PatchError(_("bad hunk #%d") % self.number)
512 foo, self.startb, foo2, bend, foo3 = m.groups() 512 foo, self.startb, foo2, bend, foo3 = m.groups()
513 self.startb = int(self.startb) 513 self.startb = int(self.startb)
514 if bend == None: 514 if bend is None:
515 bend = self.startb 515 bend = self.startb
516 self.lenb = int(bend) - self.startb 516 self.lenb = int(bend) - self.startb
517 if self.startb: 517 if self.startb:
518 self.lenb += 1 518 self.lenb += 1
519 hunki = 1 519 hunki = 1
870 current_hunk = None 870 current_hunk = None
871 gitworkdone = False 871 gitworkdone = False
872 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or 872 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or
873 ((context is not False) and x.startswith('***************')))): 873 ((context is not False) and x.startswith('***************')))):
874 try: 874 try:
875 if context == None and x.startswith('***************'): 875 if context is None and x.startswith('***************'):
876 context = True 876 context = True
877 gpatch = changed.get(bfile) 877 gpatch = changed.get(bfile)
878 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD' 878 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
879 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE' 879 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
880 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove) 880 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove)