comparison mercurial/bookmarks.py @ 32737:d6924192c0d5

bookmarks: directly use base dict 'setitem' The bmstore '__setitem__' method is setting an extra flag that is not needed during initialization. Skipping the method will allow further cleanup and yield some speedup as a side effect. Before: ! wall 0.009120 comb 0.010000 user 0.010000 sys 0.000000 (best of 312) After: ! wall 0.007874 comb 0.010000 user 0.010000 sys 0.000000 (best of 360)
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 07 Jun 2017 19:13:09 +0100
parents 173f1bdc322d
children 999aa9cfb4d3
comparison
equal deleted inserted replaced
32736:173f1bdc322d 32737:d6924192c0d5
50 def __init__(self, repo): 50 def __init__(self, repo):
51 dict.__init__(self) 51 dict.__init__(self)
52 self._repo = repo 52 self._repo = repo
53 nm = repo.changelog.nodemap 53 nm = repo.changelog.nodemap
54 tonode = bin # force local lookup 54 tonode = bin # force local lookup
55 setitem = dict.__setitem__
55 try: 56 try:
56 bkfile = _getbkfile(repo) 57 bkfile = _getbkfile(repo)
57 for line in bkfile: 58 for line in bkfile:
58 line = line.strip() 59 line = line.strip()
59 if not line: 60 if not line:
61 try: 62 try:
62 sha, refspec = line.split(' ', 1) 63 sha, refspec = line.split(' ', 1)
63 node = tonode(sha) 64 node = tonode(sha)
64 if node in nm: 65 if node in nm:
65 refspec = encoding.tolocal(refspec) 66 refspec = encoding.tolocal(refspec)
66 self[refspec] = node 67 setitem(self, refspec, node)
67 except (TypeError, ValueError): 68 except (TypeError, ValueError):
68 # - bin(...) can raise TypeError 69 # - bin(...) can raise TypeError
69 # - node in nm can raise ValueError for non-20-bytes entry 70 # - node in nm can raise ValueError for non-20-bytes entry
70 # - split(...) can raise ValueError for string without ' ' 71 # - split(...) can raise ValueError for string without ' '
71 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') 72 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')