From a50a59a9603425fafb1fac33addb201c19546808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Fri, 16 Nov 2018 13:52:11 +0300 Subject: 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 --- libraries/base/GHC/StaticPtr.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'libraries/base') 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 -- cgit v1.2.1