[pypy-commit] pypy py3.5: fix mapdict-size-limit on pypy3

cfbolz pypy.commits at gmail.com
Wed Feb 14 10:38:17 EST 2018


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.5
Changeset: r93820:ff6a031587c2
Date: 2018-02-14 16:37 +0100
http://bitbucket.org/pypy/pypy/changeset/ff6a031587c2/

Log:	fix mapdict-size-limit on pypy3

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
@@ -4,6 +4,7 @@
 from rpython.rlib.rarithmetic import intmask, r_uint
 
 from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.unicodehelper import encode_utf8
 from pypy.objspace.std.dictmultiobject import (
     W_DictMultiObject, DictStrategy, ObjectDictStrategy, BaseKeyIterator,
     BaseValueIterator, BaseItemIterator, _never_equal_to_string,
@@ -27,7 +28,7 @@
 
 # the maximum number of attributes stored in mapdict (afterwards just use a
 # dict)
-LIMIT_MAP_ATTRIBUTES = 8000
+LIMIT_MAP_ATTRIBUTES = 80
 
 
 class AbstractAttribute(object):
@@ -431,7 +432,8 @@
     def materialize_str_dict(self, space, obj, str_dict):
         new_obj = self.back.materialize_str_dict(space, obj, str_dict)
         if self.index == DICT:
-            str_dict[self.name] = obj._mapdict_read_storage(self.storageindex)
+            enc_name = encode_utf8(space, self.name)
+            str_dict[enc_name] = obj._mapdict_read_storage(self.storageindex)
         else:
             self._copy_attr(obj, new_obj)
         return new_obj
@@ -767,7 +769,7 @@
 
     def switch_to_text_strategy(self, w_dict):
         w_obj = self.unerase(w_dict.dstorage)
-        strategy = self.space.fromcache(BytesDictStrategy)
+        strategy = self.space.fromcache(UnicodeDictStrategy)
         str_dict = strategy.unerase(strategy.get_empty_storage())
         w_dict.set_strategy(strategy)
         w_dict.dstorage = strategy.erase(str_dict)
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
@@ -125,6 +125,7 @@
             obj.setdictvalue(space, str(i), i)
         # moved to dict (which is the remaining non-slot item)
         assert len(obj.storage) == 1 + numslots
+        assert isinstance(obj.getdict(space).dstrategy, UnicodeDictStrategy)
 
         for i in range(1000):
             assert obj.getdictvalue(space, str(i)) == i


More information about the pypy-commit mailing list