Mercurial > public > mercurial-scm > hg
comparison mercurial/filelog.py @ 2579:0875cda033fd
use __contains__, index or split instead of str.find
str.find return -1 when the substring is not found, -1 evaluate
to True and is a valid index, which can lead to bugs.
Using alternatives when possible makes the code clearer and less
prone to bugs. (and __contains__ is faster in microbenchmarks)
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 09 Jul 2006 01:30:30 +0200 |
parents | fe1689273f84 |
children | 345bac2bc4ec |
comparison
equal
deleted
inserted
replaced
2578:cf4f0322851d | 2579:0875cda033fd |
---|---|
32 | 32 |
33 def read(self, node): | 33 def read(self, node): |
34 t = self.revision(node) | 34 t = self.revision(node) |
35 if not t.startswith('\1\n'): | 35 if not t.startswith('\1\n'): |
36 return t | 36 return t |
37 s = t.find('\1\n', 2) | 37 s = t.index('\1\n', 2) |
38 return t[s+2:] | 38 return t[s+2:] |
39 | 39 |
40 def readmeta(self, node): | 40 def readmeta(self, node): |
41 t = self.revision(node) | 41 t = self.revision(node) |
42 if not t.startswith('\1\n'): | 42 if not t.startswith('\1\n'): |
43 return {} | 43 return {} |
44 s = t.find('\1\n', 2) | 44 s = t.index('\1\n', 2) |
45 mt = t[2:s] | 45 mt = t[2:s] |
46 m = {} | 46 m = {} |
47 for l in mt.splitlines(): | 47 for l in mt.splitlines(): |
48 k, v = l.split(": ", 1) | 48 k, v = l.split(": ", 1) |
49 m[k] = v | 49 m[k] = v |