[pypy-commit] pypy reorder-map-attributes: fixed always adding last attribute to map cache

jbs pypy.commits at gmail.com
Fri Feb 12 16:35:38 EST 2016


Author: Jasper.Schulz <jasper.b.schulz at gmail.com>
Branch: reorder-map-attributes
Changeset: r82193:a64e20eaa1db
Date: 2016-02-12 21:34 +0000
http://bitbucket.org/pypy/pypy/changeset/a64e20eaa1db/

Log:	fixed always adding last attribute to map cache

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -219,19 +219,19 @@
                         current = current.back
                 else:
                     attr._switch_map_and_write_storage(obj, w_value)
-                    stack_index = localstack_index
-                    
+                    if not localstack_index:
+                        return
+
                     if not stack_index:
-                        return
-                    
-                    # add the first attribute of the stack without reordering
-                    # to prevent an endless loop
-                    stack_index += -1
-                    next_map = stack_maps[stack_index]
-                    w_value = stack_values[stack_index]
-                    obj._get_mapdict_map()._add_attr_without_reordering(
-                        obj, next_map.name, next_map.index, w_value)
+                        # add the first attribute of the stack without reordering
+                        # to prevent an endless loop
+                        localstack_index += -1
+                        next_map = stack_maps[localstack_index]
+                        w_value = stack_values[localstack_index]
+                        obj._get_mapdict_map()._add_attr_without_reordering(
+                            obj, next_map.name, next_map.index, w_value)
 
+                    stack_index = localstack_index    
                     break
 
             if not stack_index:
diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -188,6 +188,29 @@
 
     assert obj.map is obj2.map
 
+def test_insert_different_orders_5():
+    cls = Class()
+    obj = cls.instantiate()
+    obj2 = cls.instantiate()
+    
+    obj.setdictvalue(space, "a", 10)
+    obj.setdictvalue(space, "b", 20)
+    obj.setdictvalue(space, "c", 30)
+    obj.setdictvalue(space, "d", 40)
+
+    obj2.setdictvalue(space, "d", 50)
+    obj2.setdictvalue(space, "c", 50)
+    obj2.setdictvalue(space, "b", 50)
+    obj2.setdictvalue(space, "a", 50)
+
+    obj3 = cls.instantiate()
+    obj3.setdictvalue(space, "d", 50)
+    obj3.setdictvalue(space, "c", 50)
+    obj3.setdictvalue(space, "b", 50)
+    obj3.setdictvalue(space, "a", 50)
+
+    assert obj.map is obj3.map
+
 def test_bug_stack_overflow_insert_attributes():
     cls = Class()
     obj = cls.instantiate()


More information about the pypy-commit mailing list