summaryrefslogtreecommitdiff
path: root/rts/StaticPtrTable.c
diff options
context:
space:
mode:
authorCrazycolorz5 <Crazycolorz5@gmail.com>2019-01-20 19:26:58 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-12-11 14:12:17 -0500
commitf80c4a66ae219afa7bd4172441f4e94ba649c9d9 (patch)
tree34c3aa2cc484ade9b2460ca18941763fcb101fcc /rts/StaticPtrTable.c
parent6e47a76a3d0a7b3d424442914478de579a49363c (diff)
downloadhaskell-f80c4a66ae219afa7bd4172441f4e94ba649c9d9.tar.gz
rts: Specialize hashing at call site rather than in struct.
Separate word and string hash tables on the type level, and do not store the hashing function. Thus when a different hash function is desire it is provided upon accessing the table. This is worst case the same as before the change, and in the majority of cases is better. Also mark the functions for aggressive inlining to improve performance. {F1686506} Reviewers: bgamari, erikd, simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13165 Differential Revision: https://phabricator.haskell.org/D4889
Diffstat (limited to 'rts/StaticPtrTable.c')
-rw-r--r--rts/StaticPtrTable.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/rts/StaticPtrTable.c b/rts/StaticPtrTable.c
index f5e6239ad0..9754cfad41 100644
--- a/rts/StaticPtrTable.c
+++ b/rts/StaticPtrTable.c
@@ -21,14 +21,14 @@ static Mutex spt_lock;
#endif
/// Hash function for the SPT.
-static int hashFingerprint(const HashTable *table, StgWord key) {
+STATIC_INLINE int hashFingerprint(const HashTable *table, StgWord key) {
const StgWord64* ptr = (StgWord64*) key;
// Take half of the key to compute the hash.
return hashWord(table, *(ptr + 1));
}
/// Comparison function for the SPT.
-static int compareFingerprint(StgWord a, StgWord b) {
+STATIC_INLINE int compareFingerprint(StgWord a, StgWord b) {
const StgWord64* ptra = (StgWord64*) a;
const StgWord64* ptrb = (StgWord64*) b;
return *ptra == *ptrb && *(ptra + 1) == *(ptrb + 1);
@@ -38,14 +38,14 @@ void hs_spt_insert_stableptr(StgWord64 key[2], StgStablePtr *entry) {
// hs_spt_insert is called from constructor functions, so
// the SPT needs to be initialized here.
if (spt == NULL) {
- spt = allocHashTable_(hashFingerprint, compareFingerprint);
+ spt = allocHashTable();
#if defined(THREADED_RTS)
initMutex(&spt_lock);
#endif
}
ACQUIRE_LOCK(&spt_lock);
- insertHashTable(spt, (StgWord)key, entry);
+ insertHashTable_(spt, (StgWord)key, entry, hashFingerprint);
RELEASE_LOCK(&spt_lock);
}
@@ -68,7 +68,8 @@ static void freeSptEntry(void* entry) {
void hs_spt_remove(StgWord64 key[2]) {
if (spt) {
ACQUIRE_LOCK(&spt_lock);
- StgStablePtr* entry = removeHashTable(spt, (StgWord)key, NULL);
+ StgStablePtr* entry = removeHashTable_(spt, (StgWord)key, NULL,
+ hashFingerprint, compareFingerprint);
RELEASE_LOCK(&spt_lock);
if (entry)
@@ -76,11 +77,11 @@ void hs_spt_remove(StgWord64 key[2]) {
}
}
-StgPtr hs_spt_lookup(StgWord64 key1, StgWord64 key2) {
+StgPtr hs_spt_lookup(StgWord64 key[2]) {
if (spt) {
ACQUIRE_LOCK(&spt_lock);
- StgWord64 key[2] = { key1, key2 };
- const StgStablePtr * entry = lookupHashTable(spt, (StgWord)key);
+ const StgStablePtr * entry = lookupHashTable_(spt, (StgWord)key,
+ hashFingerprint, compareFingerprint);
const StgPtr ret = entry ? deRefStablePtr(*entry) : NULL;
RELEASE_LOCK(&spt_lock);
return ret;