Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r82652:5213e8be2304 Date: 2016-03-02 12:31 +0100 http://bitbucket.org/pypy/pypy/changeset/5213e8be2304/
Log: make test_setdefault_fast pass with celldicts on pypy - reduce the nubmer of hash calls from 3 to 2 - since reducing it to 1 is impractical, adapt the test diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py --- a/pypy/objspace/std/celldict.py +++ b/pypy/objspace/std/celldict.py @@ -64,6 +64,9 @@ def setitem_str(self, w_dict, key, w_value): cell = self.getdictvalue_no_unwrapping(w_dict, key) + return self._setitem_str_cell_known(cell, w_dict, key, w_value) + + def _setitem_str_cell_known(self, cell, w_dict, key, w_value): w_value = write_cell(self.space, cell, w_value) if w_value is None: return @@ -74,10 +77,11 @@ space = self.space if space.is_w(space.type(w_key), space.w_str): key = space.str_w(w_key) - w_result = self.getitem_str(w_dict, key) + cell = self.getdictvalue_no_unwrapping(w_dict, key) + w_result = unwrap_cell(self.space, cell) if w_result is not None: return w_result - self.setitem_str(w_dict, key, w_default) + self._setitem_str_cell_known(cell, w_dict, key, w_default) return w_default else: self.switch_to_object_strategy(w_dict) diff --git a/pypy/objspace/std/test/test_celldict.py b/pypy/objspace/std/test/test_celldict.py --- a/pypy/objspace/std/test/test_celldict.py +++ b/pypy/objspace/std/test/test_celldict.py @@ -108,10 +108,11 @@ class TestModuleDictImplementation(BaseTestRDictImplementation): StrategyClass = ModuleDictStrategy - + setdefault_hash_count = 2 class TestDevolvedModuleDictImplementation(BaseTestDevolvedDictImplementation): StrategyClass = ModuleDictStrategy + setdefault_hash_count = 2 class AppTestCellDict(object): diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py --- a/pypy/objspace/std/test/test_dictmultiobject.py +++ b/pypy/objspace/std/test/test_dictmultiobject.py @@ -1248,6 +1248,9 @@ impl.setitem(x, x) assert type(impl.get_strategy()) is ObjectDictStrategy + + setdefault_hash_count = 1 + def test_setdefault_fast(self): on_pypy = "__pypy__" in sys.builtin_module_names impl = self.impl @@ -1255,11 +1258,11 @@ x = impl.setdefault(key, 1) assert x == 1 if on_pypy: - assert key.hash_count == 1 + assert key.hash_count == self.setdefault_hash_count x = impl.setdefault(key, 2) assert x == 1 if on_pypy: - assert key.hash_count == 2 + assert key.hash_count == self.setdefault_hash_count + 1 def test_fallback_evil_key(self): class F(object): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit