Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r47019:a9ad422cdb38 Date: 2011-09-02 08:54 -0400 http://bitbucket.org/pypy/pypy/changeset/a9ad422cdb38/
Log: When a key in a celldict is set with it's current value, don't create a level of indirection, or mutate the version. This shows up for the attributes of all MixedModules (including __builtins__!). diff --git a/pypy/module/pypyjit/test_pypy_c/test_globals.py b/pypy/module/pypyjit/test_pypy_c/test_globals.py --- a/pypy/module/pypyjit/test_pypy_c/test_globals.py +++ b/pypy/module/pypyjit/test_pypy_c/test_globals.py @@ -23,6 +23,4 @@ guard_not_invalidated(descr=...) p19 = getfield_gc(ConstPtr(p17), descr=<GcPtrFieldDescr .*W_DictMultiObject.inst_strategy .*>) guard_value(p19, ConstPtr(ptr20), descr=...) - p22 = getfield_gc(ConstPtr(ptr21), descr=<GcPtrFieldDescr .*ModuleCell.inst_w_value .*>) - guard_nonnull(p22, descr=...) - """) + """) \ No newline at end of file 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 @@ -65,6 +65,10 @@ if isinstance(cell, ModuleCell): cell.w_value = w_value return + # If the new value and the current value are the same, don't create a + # level of indirection, or mutate are version. + if self.space.is_w(w_value, cell): + return if cell is not None: w_value = ModuleCell(w_value) self.mutated() 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 @@ -39,6 +39,20 @@ assert d.getitem("a") is None assert d.strategy.getdictvalue_no_unwrapping(d, "a") is None + def test_same_key_set_twice(self): + strategy = ModuleDictStrategy(space) + storage = strategy.get_empty_storage() + d = W_DictMultiObject(space, strategy, storage) + + v1 = strategy.version + x = object() + d.setitem("a", x) + v2 = strategy.version + assert v1 is not v2 + d.setitem("a", x) + v3 = strategy.version + assert v2 is v3 + class AppTestModuleDict(object): def setup_class(cls): cls.space = gettestobjspace(**{"objspace.std.withcelldict": True}) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit