[pypy-svn] r68941 - in pypy/trunk/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Nov 3 16:18:04 CET 2009


Author: cfbolz
Date: Tue Nov  3 16:18:03 2009
New Revision: 68941

Modified:
   pypy/trunk/pypy/objspace/std/sharingdict.py
   pypy/trunk/pypy/objspace/std/test/test_sharingdict.py
Log:
grr, properly support deleting several attributes in a row


Modified: pypy/trunk/pypy/objspace/std/sharingdict.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/sharingdict.py	(original)
+++ pypy/trunk/pypy/objspace/std/sharingdict.py	Tue Nov  3 16:18:03 2009
@@ -129,12 +129,15 @@
             pos = self.structure.lookup_position(key)
             if pos == -1:
                 raise KeyError
-            for i in range(pos, len(self.entries)):
-                self.entries[pos] = self.entries[pos + 1]
+            struct_len = self.structure.length
+            num_back = struct_len - pos - 1
+
+            if num_back > 0:
+                for i in range(pos, struct_len):
+                    self.entries[pos] = self.entries[pos + 1]
             # don't make the entries list shorter, new keys might be added soon
-            self.entries[-1] = None
+            self.entries[struct_len - 1] = None
             structure = self.structure
-            num_back = len(self.entries) - pos - 1
             keys = [None] * num_back
             for i in range(num_back):
                 keys[i] = structure.last_key

Modified: pypy/trunk/pypy/objspace/std/test/test_sharingdict.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_sharingdict.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_sharingdict.py	Tue Nov  3 16:18:03 2009
@@ -45,3 +45,10 @@
     assert d.getitem("b") is None
     py.test.raises(KeyError, d.delitem, "b")
 
+    d.delitem("c")
+    assert d.entries == [1, None, None]
+    assert d.structure.keys == {"a": 0}
+
+    d.delitem("a")
+    assert d.entries == [None, None, None]
+    assert d.structure.keys == {}



More information about the Pypy-commit mailing list