summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2018-11-16 13:52:11 +0300
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2018-11-16 13:52:33 +0300
commita50a59a9603425fafb1fac33addb201c19546808 (patch)
tree228f87fd6e76edf2ec62a402324e47577ab0ed03
parent4efd1b487e10c8cdbc1bca10c45f0887642a5c48 (diff)
downloadhaskell-a50a59a9603425fafb1fac33addb201c19546808.tar.gz
More efficient, non-allocating unsafeLookupStaticPtr
We now allocate the key to spt on C stack rather than in Haskell heap, avoiding allocating in `unsafeLookupStaticPtr`. This should be slightly more efficient. Test Plan: Validated locally Reviewers: simonmar, hvr, bgamari, erikd Reviewed By: simonmar Subscribers: rwbarton, carter Differential Revision: https://phabricator.haskell.org/D5333
-rw-r--r--includes/HsFFI.h2
-rw-r--r--libraries/base/GHC/StaticPtr.hs7
-rw-r--r--rts/StaticPtrTable.c3
3 files changed, 6 insertions, 6 deletions
diff --git a/includes/HsFFI.h b/includes/HsFFI.h
index 84976474f5..4b6278b518 100644
--- a/includes/HsFFI.h
+++ b/includes/HsFFI.h
@@ -126,7 +126,7 @@ extern void hs_free_stable_ptr_unsafe (HsStablePtr sp);
extern void hs_free_stable_ptr (HsStablePtr sp);
extern void hs_free_fun_ptr (HsFunPtr fp);
-extern StgPtr hs_spt_lookup(StgWord64 key[2]);
+extern StgPtr hs_spt_lookup(StgWord64 key1, StgWord64 key2);
extern int hs_spt_keys(StgPtr keys[], int szKeys);
extern int hs_spt_key_count (void);
diff --git a/libraries/base/GHC/StaticPtr.hs b/libraries/base/GHC/StaticPtr.hs
index 42ca0927dc..14ff3e0b2d 100644
--- a/libraries/base/GHC/StaticPtr.hs
+++ b/libraries/base/GHC/StaticPtr.hs
@@ -48,8 +48,7 @@ module GHC.StaticPtr
) where
import Foreign.C.Types (CInt(..))
-import Foreign.Marshal (allocaArray, peekArray, withArray)
-import Foreign.Ptr (castPtr)
+import Foreign.Marshal (allocaArray, peekArray)
import GHC.Exts (addrToAny#)
import GHC.Ptr (Ptr(..), nullPtr)
import GHC.Fingerprint (Fingerprint(..))
@@ -89,13 +88,13 @@ staticKey (StaticPtr w0 w1 _ _) = Fingerprint (W64# w0) (W64# w1)
--
unsafeLookupStaticPtr :: StaticKey -> IO (Maybe (StaticPtr a))
unsafeLookupStaticPtr (Fingerprint w1 w2) = do
- ptr@(Ptr addr) <- withArray [w1,w2] (hs_spt_lookup . castPtr)
+ ptr@(Ptr addr) <- hs_spt_lookup w1 w2
if (ptr == nullPtr)
then return Nothing
else case addrToAny# addr of
(# spe #) -> return (Just spe)
-foreign import ccall unsafe hs_spt_lookup :: Ptr () -> IO (Ptr a)
+foreign import ccall unsafe hs_spt_lookup :: Word64 -> Word64 -> IO (Ptr a)
-- | A class for things buildable from static pointers.
class IsStatic p where
diff --git a/rts/StaticPtrTable.c b/rts/StaticPtrTable.c
index 0b2244025e..997987a2ce 100644
--- a/rts/StaticPtrTable.c
+++ b/rts/StaticPtrTable.c
@@ -76,9 +76,10 @@ void hs_spt_remove(StgWord64 key[2]) {
}
}
-StgPtr hs_spt_lookup(StgWord64 key[2]) {
+StgPtr hs_spt_lookup(StgWord64 key1, StgWord64 key2) {
if (spt) {
ACQUIRE_LOCK(&spt_lock);
+ StgWord64 key[2] = { key1, key2 };
const StgStablePtr * entry = lookupHashTable(spt, (StgWord)key);
const StgPtr ret = entry ? deRefStablePtr(*entry) : NULL;
RELEASE_LOCK(&spt_lock);