Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: remove-objspace-options Changeset: r83817:ef01c84d0a87 Date: 2016-04-22 10:06 +0300 http://bitbucket.org/pypy/pypy/changeset/ef01c84d0a87/
Log: remove withidentitydict option and make that always on diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -249,9 +249,6 @@ "cache and shortcut calling __new__ from builtin types", default=False), - BoolOption("withidentitydict", - "track types that override __hash__, __eq__ or __cmp__ and use a special dict strategy for those which do not", - default=False), ]), ]) @@ -272,7 +269,6 @@ config.objspace.std.suggest(getattributeshortcut=True) #config.objspace.std.suggest(newshortcut=True) config.objspace.std.suggest(withspecialisedtuple=True) - config.objspace.std.suggest(withidentitydict=True) #if not IS_64_BITS: # config.objspace.std.suggest(withsmalllong=True) diff --git a/pypy/doc/config/objspace.std.withidentitydict.txt b/pypy/doc/config/objspace.std.withidentitydict.txt deleted file mode 100644 --- a/pypy/doc/config/objspace.std.withidentitydict.txt +++ /dev/null @@ -1,21 +0,0 @@ -============================= -objspace.std.withidentitydict -============================= - -* **name:** withidentitydict - -* **description:** enable a dictionary strategy for "by identity" comparisons - -* **command-line:** --objspace-std-withidentitydict - -* **command-line for negation:** --no-objspace-std-withidentitydict - -* **option type:** boolean option - -* **default:** True - - -Enable a dictionary strategy specialized for instances of classes which -compares "by identity", which is the default unless you override ``__hash__``, -``__eq__`` or ``__cmp__``. This strategy will be used only with new-style -classes. diff --git a/pypy/doc/interpreter-optimizations.rst b/pypy/doc/interpreter-optimizations.rst --- a/pypy/doc/interpreter-optimizations.rst +++ b/pypy/doc/interpreter-optimizations.rst @@ -62,29 +62,37 @@ Dictionary Optimizations ~~~~~~~~~~~~~~~~~~~~~~~~ -Multi-Dicts -+++++++++++ +Dict Strategies +++++++++++++++++ -Multi-dicts are a special implementation of dictionaries. It became clear that -it is very useful to *change* the internal representation of an object during -its lifetime. Multi-dicts are a general way to do that for dictionaries: they -provide generic support for the switching of internal representations for -dicts. +Dict strategies are an implementation approach for dictionaries (and lists) +that make it possible to use a specialized representation of the dictionary's +data, while still being able to switch back to a general representation should +that become necessary later. -If you just enable multi-dicts, special representations for empty dictionaries, -for string-keyed dictionaries. In addition there are more specialized dictionary -implementations for various purposes (see below). +Dict strategies are always enabled, by default there are special strategies for +dicts with just string keys, just unicode keys and just integer keys. If one of +those specialized strategies is used, then dict lookup can use much faster +hashing and comparison for the dict keys. There is of course also a strategy +for general keys. -This is now the default implementation of dictionaries in the Python interpreter. +Identity Dicts ++++++++++++++++ -Sharing Dicts +We also have a strategy specialized for keys that are instances of classes +which compares "by identity", which is the default unless you override +``__hash__``, ``__eq__`` or ``__cmp__``. This strategy will be used only with +new-style classes. + + +Map Dicts +++++++++++++ -Sharing dictionaries are a special representation used together with multidicts. -This dict representation is used only for instance dictionaries and tries to -make instance dictionaries use less memory (in fact, in the ideal case the -memory behaviour should be mostly like that of using __slots__). +Map dictionaries are a special representation used together with dict strategies. +This dict strategy is used only for instance dictionaries and tries to +make instance dictionaries use less memory (in fact, usually memory behaviour +should be mostly like that of using ``__slots__``). The idea is the following: Most instances of the same class have very similar attributes, and are even adding these keys to the dictionary in the same order @@ -95,8 +103,6 @@ dicts: the representation of the instance dict contains only a list of values. -A more advanced version of sharing dicts, called *map dicts,* is available -with the :config:`objspace.std.withmapdict` option. List Optimizations diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py --- a/pypy/objspace/std/dictmultiobject.py +++ b/pypy/objspace/std/dictmultiobject.py @@ -592,7 +592,6 @@ return self.erase(None) def switch_to_correct_strategy(self, w_dict, w_key): - withidentitydict = self.space.config.objspace.std.withidentitydict if type(w_key) is self.space.StringObjectCls: self.switch_to_bytes_strategy(w_dict) return @@ -602,7 +601,7 @@ w_type = self.space.type(w_key) if self.space.is_w(w_type, self.space.w_int): self.switch_to_int_strategy(w_dict) - elif withidentitydict and w_type.compares_by_identity(): + elif w_type.compares_by_identity(): self.switch_to_identity_strategy(w_dict) else: self.switch_to_object_strategy(w_dict) 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 @@ -1115,7 +1115,6 @@ class std: withsmalldicts = False withcelldict = False - withidentitydict = False withmapdict = False FakeSpace.config = Config() diff --git a/pypy/objspace/std/test/test_identitydict.py b/pypy/objspace/std/test/test_identitydict.py --- a/pypy/objspace/std/test/test_identitydict.py +++ b/pypy/objspace/std/test/test_identitydict.py @@ -2,7 +2,6 @@ from pypy.interpreter.gateway import interp2app class AppTestComparesByIdentity: - spaceconfig = {"objspace.std.withidentitydict": True} def setup_class(cls): from pypy.objspace.std import identitydict @@ -56,7 +55,6 @@ class AppTestIdentityDict(object): - spaceconfig = {"objspace.std.withidentitydict": True} def setup_class(cls): if cls.runappdirect: diff --git a/pypy/objspace/std/test/test_identityset.py b/pypy/objspace/std/test/test_identityset.py --- a/pypy/objspace/std/test/test_identityset.py +++ b/pypy/objspace/std/test/test_identityset.py @@ -3,9 +3,6 @@ class AppTestIdentitySet(object): - # needed for compares_by_identity - spaceconfig = {"objspace.std.withidentitydict": True} - def setup_class(cls): from pypy.objspace.std import identitydict if cls.runappdirect: diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py --- a/pypy/objspace/std/typeobject.py +++ b/pypy/objspace/std/typeobject.py @@ -124,6 +124,7 @@ "flag_cpytype", "flag_abstract?", "flag_sequence_bug_compat", + "compares_by_identity_status?", 'needsdel', 'weakrefable', 'hasdict', @@ -138,7 +139,7 @@ # (False is a conservative default, fixed during real usage) uses_object_getattribute = False - # for config.objspace.std.withidentitydict + # for the IdentityDictStrategy compares_by_identity_status = UNKNOWN # used to cache the type's __new__ function @@ -199,10 +200,9 @@ w_self.uses_object_getattribute = False # ^^^ conservative default, fixed during real usage - if space.config.objspace.std.withidentitydict: - if (key is None or key == '__eq__' or - key == '__cmp__' or key == '__hash__'): - w_self.compares_by_identity_status = UNKNOWN + if (key is None or key == '__eq__' or + key == '__cmp__' or key == '__hash__'): + w_self.compares_by_identity_status = UNKNOWN if space.config.objspace.std.newshortcut: w_self.w_new_function = None @@ -253,8 +253,6 @@ def compares_by_identity(w_self): from pypy.objspace.descroperation import object_hash, type_eq - if not w_self.space.config.objspace.std.withidentitydict: - return False # conservative # if w_self.compares_by_identity_status != UNKNOWN: # fast path _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit