Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: rdict-fast-hash Changeset: r93372:de9aa6bbf0f7 Date: 2017-12-11 20:34 +0100 http://bitbucket.org/pypy/pypy/changeset/de9aa6bbf0f7/
Log: rename the argument to simple_hash_eq, as suggested by antocuni and arigato diff --git a/pypy/module/_pypyjson/interp_decoder.py b/pypy/module/_pypyjson/interp_decoder.py --- a/pypy/module/_pypyjson/interp_decoder.py +++ b/pypy/module/_pypyjson/interp_decoder.py @@ -71,7 +71,7 @@ self.ll_chars = rffi.str2charp(s) self.end_ptr = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw') self.pos = 0 - self.cache = r_dict(slice_eq, slice_hash, fast_hash=True) + self.cache = r_dict(slice_eq, slice_hash, simple_hash_eq=True) def close(self): rffi.free_charp(self.ll_chars) diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -194,14 +194,14 @@ listdef.generalize_range_step(flags['range_step']) return SomeList(listdef) - def getdictdef(self, is_r_dict=False, force_non_null=False, fast_hash=False): + def getdictdef(self, is_r_dict=False, force_non_null=False, simple_hash_eq=False): """Get the DictDef associated with the current position.""" try: dictdef = self.dictdefs[self.position_key] except KeyError: dictdef = DictDef(self, is_r_dict=is_r_dict, force_non_null=force_non_null, - fast_hash=fast_hash) + simple_hash_eq=simple_hash_eq) self.dictdefs[self.position_key] = dictdef return dictdef diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -237,28 +237,28 @@ return SomeInstance(clsdef) @analyzer_for(rpython.rlib.objectmodel.r_dict) -def robjmodel_r_dict(s_eqfn, s_hashfn, s_force_non_null=None, s_fast_hash=None): - return _r_dict_helper(SomeDict, s_eqfn, s_hashfn, s_force_non_null, s_fast_hash) +def robjmodel_r_dict(s_eqfn, s_hashfn, s_force_non_null=None, s_simple_hash_eq=None): + return _r_dict_helper(SomeDict, s_eqfn, s_hashfn, s_force_non_null, s_simple_hash_eq) @analyzer_for(rpython.rlib.objectmodel.r_ordereddict) -def robjmodel_r_ordereddict(s_eqfn, s_hashfn, s_force_non_null=None, s_fast_hash=None): +def robjmodel_r_ordereddict(s_eqfn, s_hashfn, s_force_non_null=None, s_simple_hash_eq=None): return _r_dict_helper(SomeOrderedDict, s_eqfn, s_hashfn, - s_force_non_null, s_fast_hash) + s_force_non_null, s_simple_hash_eq) -def _r_dict_helper(cls, s_eqfn, s_hashfn, s_force_non_null, s_fast_hash): +def _r_dict_helper(cls, s_eqfn, s_hashfn, s_force_non_null, s_simple_hash_eq): if s_force_non_null is None: force_non_null = False else: assert s_force_non_null.is_constant() force_non_null = s_force_non_null.const - if s_fast_hash is None: - fast_hash = False + if s_simple_hash_eq is None: + simple_hash_eq = False else: - assert s_fast_hash.is_constant() - fast_hash = s_fast_hash.const + assert s_simple_hash_eq.is_constant() + simple_hash_eq = s_simple_hash_eq.const dictdef = getbookkeeper().getdictdef(is_r_dict=True, force_non_null=force_non_null, - fast_hash=fast_hash) + simple_hash_eq=simple_hash_eq) dictdef.dictkey.update_rdict_annotations(s_eqfn, s_hashfn) return cls(dictdef) diff --git a/rpython/annotator/dictdef.py b/rpython/annotator/dictdef.py --- a/rpython/annotator/dictdef.py +++ b/rpython/annotator/dictdef.py @@ -82,13 +82,13 @@ s_value = s_ImpossibleValue, is_r_dict = False, force_non_null = False, - fast_hash = False): + simple_hash_eq = False): self.dictkey = DictKey(bookkeeper, s_key, is_r_dict) self.dictkey.itemof[self] = True self.dictvalue = DictValue(bookkeeper, s_value) self.dictvalue.itemof[self] = True self.force_non_null = force_non_null - self.fast_hash = fast_hash + self.simple_hash_eq = simple_hash_eq def read_key(self, position_key): self.dictkey.read_locations.add(position_key) diff --git a/rpython/jit/metainterp/typesystem.py b/rpython/jit/metainterp/typesystem.py --- a/rpython/jit/metainterp/typesystem.py +++ b/rpython/jit/metainterp/typesystem.py @@ -106,11 +106,11 @@ # It is an r_dict on lltype. Two copies, to avoid conflicts with # the value type. Note that NULL is not allowed as a key. def new_ref_dict(self): - return r_dict(rd_eq, rd_hash, fast_hash=True) + return r_dict(rd_eq, rd_hash, simple_hash_eq=True) def new_ref_dict_2(self): - return r_dict(rd_eq, rd_hash, fast_hash=True) + return r_dict(rd_eq, rd_hash, simple_hash_eq=True) def new_ref_dict_3(self): - return r_dict(rd_eq, rd_hash, fast_hash=True) + return r_dict(rd_eq, rd_hash, simple_hash_eq=True) def cast_vtable_to_hashable(self, cpu, ptr): adr = llmemory.cast_ptr_to_adr(ptr) diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py --- a/rpython/rlib/objectmodel.py +++ b/rpython/rlib/objectmodel.py @@ -748,11 +748,11 @@ def _newdict(self): return {} - def __init__(self, key_eq, key_hash, force_non_null=False, fast_hash=False): + def __init__(self, key_eq, key_hash, force_non_null=False, simple_hash_eq=False): """ force_non_null=True means that the key can never be None (even if the annotator things it could be) - fast_hash=True means that the hash function is very fast, meaning it's + simple_hash_eq=True means that the hash function is very fast, meaning it's efficient enough that the dict does not have to store the hash per key. It also implies that neither the hash nor the eq function will mutate the dictionary. """ @@ -760,7 +760,7 @@ self.key_eq = key_eq self.key_hash = key_hash self.force_non_null = force_non_null - self.fast_hash = fast_hash + self.simple_hash_eq = simple_hash_eq def __getitem__(self, key): return self._dict[_r_dictkey(self, key)] diff --git a/rpython/rlib/test/test_objectmodel.py b/rpython/rlib/test/test_objectmodel.py --- a/rpython/rlib/test/test_objectmodel.py +++ b/rpython/rlib/test/test_objectmodel.py @@ -332,7 +332,7 @@ def test_r_dict_fast_functions(self): def fn(): - d1 = r_dict(strange_key_eq, strange_key_hash, fast_hash=True) + d1 = r_dict(strange_key_eq, strange_key_hash, simple_hash_eq=True) return play_with_r_dict(d1) res = self.interpret(fn, []) assert res diff --git a/rpython/rtyper/lltypesystem/rordereddict.py b/rpython/rtyper/lltypesystem/rordereddict.py --- a/rpython/rtyper/lltypesystem/rordereddict.py +++ b/rpython/rtyper/lltypesystem/rordereddict.py @@ -66,7 +66,7 @@ def get_ll_dict(DICTKEY, DICTVALUE, get_custom_eq_hash=None, DICT=None, ll_fasthash_function=None, ll_hash_function=None, - ll_eq_function=None, method_cache={}, fast_hash=False, + ll_eq_function=None, method_cache={}, simple_hash_eq=False, dummykeyobj=None, dummyvalueobj=None, rtyper=None): # get the actual DICT type. if DICT is None, it's created, otherwise # forward reference is becoming DICT @@ -114,7 +114,7 @@ # * the value entryfields.append(("value", DICTVALUE)) - if fast_hash: + if simple_hash_eq: assert get_custom_eq_hash is not None entrymeths['entry_hash'] = ll_hash_custom_fast elif ll_fasthash_function is None: @@ -143,7 +143,7 @@ 'keyeq': ll_keyeq_custom, 'r_rdict_eqfn': r_rdict_eqfn, 'r_rdict_hashfn': r_rdict_hashfn, - 'paranoia': not fast_hash, + 'paranoia': not simple_hash_eq, } else: # figure out which functions must be used to hash and compare @@ -170,14 +170,14 @@ class OrderedDictRepr(AbstractDictRepr): def __init__(self, rtyper, key_repr, value_repr, dictkey, dictvalue, - custom_eq_hash=None, force_non_null=False, fast_hash=False): + custom_eq_hash=None, force_non_null=False, simple_hash_eq=False): #assert not force_non_null self.rtyper = rtyper self.finalized = False self.DICT = lltype.GcForwardReference() self.lowleveltype = lltype.Ptr(self.DICT) self.custom_eq_hash = custom_eq_hash is not None - self.fast_hash = fast_hash + self.simple_hash_eq = simple_hash_eq if not isinstance(key_repr, rmodel.Repr): # not computed yet, done by setup() assert callable(key_repr) self._key_repr_computer = key_repr @@ -215,7 +215,7 @@ self.r_rdict_eqfn, self.r_rdict_hashfn = ( self._custom_eq_hash_repr()) kwd['get_custom_eq_hash'] = self._custom_eq_hash_repr - kwd['fast_hash'] = self.fast_hash + kwd['simple_hash_eq'] = self.simple_hash_eq else: kwd['ll_hash_function'] = self.key_repr.get_ll_hash_function() kwd['ll_eq_function'] = self.key_repr.get_ll_eq_function() diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py --- a/rpython/rtyper/rbuiltin.py +++ b/rpython/rtyper/rbuiltin.py @@ -717,8 +717,8 @@ @typer_for(OrderedDict) @typer_for(objectmodel.r_dict) @typer_for(objectmodel.r_ordereddict) -def rtype_dict_constructor(hop, i_force_non_null=None, i_fast_hash=None): - # 'i_force_non_null' and 'i_fast_hash' are ignored here; if they have any +def rtype_dict_constructor(hop, i_force_non_null=None, i_simple_hash_eq=None): + # 'i_force_non_null' and 'i_simple_hash_eq' are ignored here; if they have any # effect, it has already been applied to 'hop.r_result' hop.exception_cannot_occur() r_dict = hop.r_result diff --git a/rpython/rtyper/rdict.py b/rpython/rtyper/rdict.py --- a/rpython/rtyper/rdict.py +++ b/rpython/rtyper/rdict.py @@ -15,7 +15,7 @@ s_key = dictkey.s_value s_value = dictvalue.s_value force_non_null = self.dictdef.force_non_null - fast_hash = self.dictdef.fast_hash + simple_hash_eq = self.dictdef.simple_hash_eq if dictkey.custom_eq_hash: custom_eq_hash = lambda: (rtyper.getrepr(dictkey.s_rdict_eqfn), rtyper.getrepr(dictkey.s_rdict_hashfn)) @@ -23,7 +23,7 @@ custom_eq_hash = None return self.get_dict_repr()(rtyper, lambda: rtyper.getrepr(s_key), lambda: rtyper.getrepr(s_value), dictkey, dictvalue, - custom_eq_hash, force_non_null, fast_hash) + custom_eq_hash, force_non_null, simple_hash_eq) def rtyper_makekey(self): self.dictdef.dictkey .dont_change_any_more = True diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -544,7 +544,7 @@ def myhash(n): return ~n def f(): - d = self.new_r_dict(myeq, myhash, fast_hash=True) + d = self.new_r_dict(myeq, myhash, simple_hash_eq=True) d[5] = 7 d[12] = 19 return d @@ -1019,8 +1019,8 @@ return {} @staticmethod - def new_r_dict(myeq, myhash, force_non_null=False, fast_hash=False): - return r_dict(myeq, myhash, force_non_null=force_non_null, fast_hash=fast_hash) + def new_r_dict(myeq, myhash, force_non_null=False, simple_hash_eq=False): + return r_dict(myeq, myhash, force_non_null=force_non_null, simple_hash_eq=simple_hash_eq) def test_two_dicts_with_different_value_types(self): def func(i): diff --git a/rpython/rtyper/test/test_rordereddict.py b/rpython/rtyper/test/test_rordereddict.py --- a/rpython/rtyper/test/test_rordereddict.py +++ b/rpython/rtyper/test/test_rordereddict.py @@ -386,8 +386,10 @@ return OrderedDict() @staticmethod - def new_r_dict(myeq, myhash, force_non_null=False, fast_hash=False): - return objectmodel.r_ordereddict(myeq, myhash, force_non_null=force_non_null, fast_hash=fast_hash) + def new_r_dict(myeq, myhash, force_non_null=False, simple_hash_eq=False): + return objectmodel.r_ordereddict( + myeq, myhash, force_non_null=force_non_null, + simple_hash_eq=simple_hash_eq) def test_two_dicts_with_different_value_types(self): def func(i): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit