[pypy-commit] pypy rdict-fast-hash: small refactoring: rename ENTRIES.hash to .entry_hash (hash is super hard to

cfbolz pypy.commits at gmail.com
Mon Dec 11 11:40:49 EST 2017


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: rdict-fast-hash
Changeset: r93365:cba7d424ef73
Date: 2017-12-11 17:23 +0100
http://bitbucket.org/pypy/pypy/changeset/cba7d424ef73/

Log:	small refactoring: rename ENTRIES.hash to .entry_hash (hash is super
	hard to grep for), also make it take the dict in preparation for
	r_dict supporting fast hash functions

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
@@ -116,9 +116,9 @@
 
     if ll_fasthash_function is None:
         entryfields.append(("f_hash", lltype.Signed))
-        entrymeths['hash'] = ll_hash_from_cache
+        entrymeths['entry_hash'] = ll_hash_from_cache
     else:
-        entrymeths['hash'] = ll_hash_recomputed
+        entrymeths['entry_hash'] = ll_hash_recomputed
         entrymeths['fasthashfn'] = ll_fasthash_function
 
     # Build the lltype data structures
@@ -600,12 +600,12 @@
     dummy = ENTRIES.dummy_obj.ll_dummy_value
     entries[i].value = dummy
 
- at signature(types.any(), types.int(), returns=types.any())
-def ll_hash_from_cache(entries, i):
+ at signature(types.any(), types.any(), types.int(), returns=types.any())
+def ll_hash_from_cache(entries, d, i):
     return entries[i].f_hash
 
- at signature(types.any(), types.int(), returns=types.any())
-def ll_hash_recomputed(entries, i):
+ at signature(types.any(), types.any(), types.int(), returns=types.any())
+def ll_hash_recomputed(entries, d, i):
     ENTRIES = lltype.typeOf(entries).TO
     return ENTRIES.fasthashfn(entries[i].key)
 
@@ -962,22 +962,22 @@
     if fun == FUNC_BYTE:
         while i < ibound:
             if entries.valid(i):
-                ll_dict_store_clean(d, entries.hash(i), i, TYPE_BYTE)
+                ll_dict_store_clean(d, entries.entry_hash(d, i), i, TYPE_BYTE)
             i += 1
     elif fun == FUNC_SHORT:
         while i < ibound:
             if entries.valid(i):
-                ll_dict_store_clean(d, entries.hash(i), i, TYPE_SHORT)
+                ll_dict_store_clean(d, entries.entry_hash(d, i), i, TYPE_SHORT)
             i += 1
     elif IS_64BIT and fun == FUNC_INT:
         while i < ibound:
             if entries.valid(i):
-                ll_dict_store_clean(d, entries.hash(i), i, TYPE_INT)
+                ll_dict_store_clean(d, entries.entry_hash(d, i), i, TYPE_INT)
             i += 1
     elif fun == FUNC_LONG:
         while i < ibound:
             if entries.valid(i):
-                ll_dict_store_clean(d, entries.hash(i), i, TYPE_LONG)
+                ll_dict_store_clean(d, entries.entry_hash(d, i), i, TYPE_LONG)
             i += 1
     else:
         assert False
@@ -1015,7 +1015,7 @@
         checkingkey = entries[index - VALID_OFFSET].key
         if direct_compare and checkingkey == key:
             return index - VALID_OFFSET   # found the entry
-        if d.keyeq is not None and entries.hash(index - VALID_OFFSET) == hash:
+        if d.keyeq is not None and entries.entry_hash(d, index - VALID_OFFSET) == hash:
             # correct hash, maybe the key is e.g. a different pointer to
             # an equal object
             found = d.keyeq(checkingkey, key)
@@ -1056,7 +1056,7 @@
             checkingkey = entries[index - VALID_OFFSET].key
             if direct_compare and checkingkey == key:
                 return index - VALID_OFFSET   # found the entry
-            if d.keyeq is not None and entries.hash(index - VALID_OFFSET) == hash:
+            if d.keyeq is not None and entries.entry_hash(d, index - VALID_OFFSET) == hash:
                 # correct hash, maybe the key is e.g. a different pointer to
                 # an equal object
                 found = d.keyeq(checkingkey, key)
@@ -1305,14 +1305,14 @@
 def ll_dict_update(dic1, dic2):
     if dic1 == dic2:
         return
-    ll_ensure_indexes(dic2)    # needed for entries.hash() below
+    ll_ensure_indexes(dic2)    # needed for entries.entry_hash() below
     ll_prepare_dict_update(dic1, dic2.num_live_items)
     i = 0
     while i < dic2.num_ever_used_items:
         entries = dic2.entries
         if entries.valid(i):
             entry = entries[i]
-            hash = entries.hash(i)
+            hash = entries.entry_hash(dic2, i)
             key = entry.key
             value = entry.value
             index = dic1.lookup_function(dic1, key, hash, FLAG_STORE)
@@ -1413,7 +1413,7 @@
     r = lltype.malloc(ELEM.TO)
     r.item0 = recast(ELEM.TO.item0, entry.key)
     r.item1 = recast(ELEM.TO.item1, entry.value)
-    _ll_dict_del(dic, dic.entries.hash(i), i)
+    _ll_dict_del(dic, dic.entries.entry_hash(dic, i), i)
     return r
 
 def ll_dict_pop(dic, key):


More information about the pypy-commit mailing list