Mercurial > hg
view tests/test-dicthelpers.py @ 22503:300e07582e9b stable
revset: add an optimised baseset.__contains__ (issue4371)
The baseset class is based on a python list. This means that base.__contains__
was absolutely as crappy as list.__contains__. We now rely on __contains__ from
the underlying set.
This will avoid having to explicitly convert the baseset to a set (using
baseset.set()) whenever one want fast membership test.
Apparently there is already code that forgot to do such conversions since we
observe a massive speedup in some test.
revset #25: roots((0::) - (0::tip))
0) wall 2.079454 comb 2.080000 user 2.080000 sys 0.000000 (best of 5)
1) wall 0.132970 comb 0.130000 user 0.130000 sys 0.000000 (best of 65)
No regression is observed in benchmarks.
This change improve the issue4371 back to acceptable situation (but are still
slower than manual substraction)
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 16 Sep 2014 23:59:29 -0700 |
parents | ed46c2b98b0d |
children |
line wrap: on
line source
from mercurial.dicthelpers import diff, join import unittest import silenttestrunner class testdicthelpers(unittest.TestCase): def test_dicthelpers(self): # empty dicts self.assertEqual(diff({}, {}), {}) self.assertEqual(join({}, {}), {}) d1 = {} d1['a'] = 'foo' d1['b'] = 'bar' d1['c'] = 'baz' # same identity self.assertEqual(diff(d1, d1), {}) self.assertEqual(join(d1, d1), {'a': ('foo', 'foo'), 'b': ('bar', 'bar'), 'c': ('baz', 'baz')}) # vs empty self.assertEqual(diff(d1, {}), {'a': ('foo', None), 'b': ('bar', None), 'c': ('baz', None)}) self.assertEqual(diff(d1, {}), {'a': ('foo', None), 'b': ('bar', None), 'c': ('baz', None)}) d2 = {} d2['a'] = 'foo2' d2['b'] = 'bar' d2['d'] = 'quux' self.assertEqual(diff(d1, d2), {'a': ('foo', 'foo2'), 'c': ('baz', None), 'd': (None, 'quux')}) self.assertEqual(join(d1, d2), {'a': ('foo', 'foo2'), 'b': ('bar', 'bar'), 'c': ('baz', None), 'd': (None, 'quux')}) # with default argument self.assertEqual(diff(d1, d2, 123), {'a': ('foo', 'foo2'), 'c': ('baz', 123), 'd': (123, 'quux')}) self.assertEqual(join(d1, d2, 456), {'a': ('foo', 'foo2'), 'b': ('bar', 'bar'), 'c': ('baz', 456), 'd': (456, 'quux')}) # check that we compare against default self.assertEqual(diff(d1, d2, 'baz'), {'a': ('foo', 'foo2'), 'd': ('baz', 'quux')}) self.assertEqual(diff(d1, d2, 'quux'), {'a': ('foo', 'foo2'), 'c': ('baz', 'quux')}) if __name__ == '__main__': silenttestrunner.main(__name__)