X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FStringBuffer.lhs;h=2b3b775791e0cdcdde57b363e08ffe86305c0a60;hb=9aad47f1162666431deee99884c523b1ff69cf98;hp=a89c0d2ba98dca11c15ff5019acfc5c34aeaa248;hpb=e761a777f2440ca1b8d8b40848cc5aa30d889ff6;p=ghc-hetmet.git diff --git a/compiler/utils/StringBuffer.lhs b/compiler/utils/StringBuffer.lhs index a89c0d2..2b3b775 100644 --- a/compiler/utils/StringBuffer.lhs +++ b/compiler/utils/StringBuffer.lhs @@ -6,6 +6,10 @@ Buffers for scanning string input stored in external arrays. \begin{code} +{-# OPTIONS_GHC -O -funbox-strict-fields #-} +-- We always optimise this, otherwise performance of a non-optimised +-- compiler is severely affected + module StringBuffer ( StringBuffer(..), @@ -75,7 +79,7 @@ data StringBuffer instance Show StringBuffer where showsPrec _ s = showString "" + . showString ")>" -- ----------------------------------------------------------------------------- -- Creation / Destruction @@ -125,12 +129,14 @@ appendStringBuffers sb1 sb2 withForeignPtr newBuf $ \ptr -> withForeignPtr (buf sb1) $ \sb1Ptr -> withForeignPtr (buf sb2) $ \sb2Ptr -> - do copyArray (sb1Ptr `advancePtr` cur sb1) ptr (calcLen sb1) - copyArray (sb2Ptr `advancePtr` cur sb2) (ptr `advancePtr` cur sb1) (calcLen sb2) + do copyArray ptr (sb1Ptr `advancePtr` cur sb1) sb1_len + copyArray (ptr `advancePtr` sb1_len) (sb2Ptr `advancePtr` cur sb2) sb2_len pokeArray (ptr `advancePtr` size) [0,0,0] return (StringBuffer newBuf size 0) - where calcLen sb = len sb - cur sb - size = calcLen sb1 + calcLen sb2 + where sb1_len = calcLen sb1 + sb2_len = calcLen sb2 + calcLen sb = len sb - cur sb + size = sb1_len + sb2_len stringToStringBuffer :: String -> IO StringBuffer stringToStringBuffer str = do @@ -218,7 +224,7 @@ parseUnsignedInteger (StringBuffer buf _ cur) len radix char_to_int --LOL, in implementations where the indexing needs slow unsafePerformIO, --this is less (not more) efficient than using the IO monad explicitly --here. - ptr' = pUnbox ptr + !ptr' = pUnbox ptr byteOff i = cBox (indexWord8OffFastPtrAsFastChar ptr' (iUnbox (cur + i))) go i x | i == len = x | otherwise = case byteOff i of