Mercurial > hg
diff contrib/hgdiff @ 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 | ea7b982b6c08 |
children | 31177742f54a |
line wrap: on
line diff
--- a/contrib/hgdiff Wed May 20 00:43:23 2009 +0200 +++ b/contrib/hgdiff Wed May 20 00:52:46 2009 +0200 @@ -37,13 +37,13 @@ names[os.path.join(l, x)] = (st.st_dev, st.st_ino) def diff_files(file1, file2): - if file1 == None: + if file1 is None: b = file(file2).read().splitlines(1) l1 = "--- %s\n" % (file2) l2 = "+++ %s\n" % (file2) l3 = "@@ -0,0 +1,%d @@\n" % len(b) l = [l1, l2, l3] + ["+" + e for e in b] - elif file2 == None: + elif file2 is None: a = file(file1).read().splitlines(1) l1 = "--- %s\n" % (file1) l2 = "+++ %s\n" % (file1)