From 7651b6799523e55e132ed8f5ccd5bb3f21b9a0ac Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 13 Dec 2012 20:20:58 +0000 Subject: Make FastBytes a synonym for ByteString A step on the way to getting rid of FastBytes slow nofib Compile times look like: -1 s.d. -2.4% +1 s.d. +3.4% Average +0.4% but looking at the times for the longer-running compilations I think the change is just noise. --- compiler/ghci/ByteCodeGen.lhs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'compiler/ghci') diff --git a/compiler/ghci/ByteCodeGen.lhs b/compiler/ghci/ByteCodeGen.lhs index 2b332a4581..9c9526de27 100644 --- a/compiler/ghci/ByteCodeGen.lhs +++ b/compiler/ghci/ByteCodeGen.lhs @@ -63,6 +63,8 @@ import BreakArray import Data.Maybe import Module +import qualified Data.ByteString as BS +import qualified Data.ByteString.Unsafe as BS import Data.Map (Map) import qualified Data.Map as Map import qualified FiniteMap as Map @@ -1266,18 +1268,18 @@ pushAtom _ _ (AnnLit lit) = do where pushStr s = let getMallocvilleAddr - = case s of - FastBytes n fp -> + = -- we could grab the Ptr from the ForeignPtr, -- but then we have no way to control its lifetime. -- In reality it'll probably stay alive long enoungh -- by virtue of the global FastString table, but -- to be on the safe side we copy the string into -- a malloc'd area of memory. - do ptr <- ioToBc (mallocBytes (n+1)) + do let n = BS.length s + ptr <- ioToBc (mallocBytes (n+1)) recordMallocBc ptr ioToBc ( - withForeignPtr fp $ \p -> do + BS.unsafeUseAsCString s $ \p -> do memcpy ptr p (fromIntegral n) pokeByteOff ptr n (fromIntegral (ord '\0') :: Word8) return ptr -- cgit v1.2.1