templater: back out 0615b22da148, it breaks schemes ({1})
dicthelpers.diff: compare against default for missing values

This is not only a bit faster, but also aligns with callers' expectations
better since we can legitimately have manifestdict's _flags set to '' instead
of unset.

hg perfmergecalculate -r .
before: ! wall 0.139582 comb 0.140000 user 0.140000 sys 0.000000 (best of 59)
after:  ! wall 0.126154 comb 0.120000 user 0.120000 sys 0.000000 (best of 74)

hg perfmergecalculate -r .^
before: ! wall 0.236333 comb 0.240000 user 0.240000 sys 0.000000 (best of 36)
after:  ! wall 0.212265 comb 0.210000 user 0.210000 sys 0.000000 (best of 45)
manifestmerge: handle workdir removed, remote removed with flags

This can happen when a file with flags is removed or deleted in the working
directory and also not present in m2. The obvious solution is to add a
__delitem__ override to manifestdict that removes the file from flags if
necessary, but that has a significant performance cost in some cases, e.g.
hg status --rev rev1 --rev rev2 <file>.
merge
scmutil: migrate finddirs from dirstate
scmutil: add a dirs class

This encapsulates the "multiset of directories" structures that are
currently open-coded (and duplicated) in both the dirstate and
context modules.

This will be used, and optionally replaced by a C implementation,
in upcoming changes.
scmutil: use new dirs class in dirstate and context

The multiset-of-directories code was open coded in each of these
modules; this change gets rid of the duplication.
scmutil: rewrite dirs in C, use if available

This is over twice as fast as the Python dirs code. Upcoming changes
will nearly double its speed again.

perfdirs results for a working dir with 170,000 files:
  Python     638 msec
  C          244
dirs: use mutable integers internally

These integers are not visible to Python code, so this is safe.

perfdirs results for a working dir with 170,000 files:
  Python     638 msec
  C          244
  C+int      192
dirs: use mutable strings internally

perfdirs results for a working dir with 170,000 files:
  Python     638 msec
  C          244
  C+int      192
  C+int+str  168

In the large repo above, the nearly 0.5 second time improvement is
visible in commands like "hg add" and "hg update".

hg add
  Python    1100 msec
  C+int+str  600

hg update (with nothing to do)
  Python    2800 msec
  C+int+str 2240