projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fold constants during forward substitution in the Cmm mini-inliner
[ghc-hetmet.git]
/
compiler
/
utils
/
StringBuffer.lhs
diff --git
a/compiler/utils/StringBuffer.lhs
b/compiler/utils/StringBuffer.lhs
index
d51c800
..
5d1bfa6
100644
(file)
--- a/
compiler/utils/StringBuffer.lhs
+++ b/
compiler/utils/StringBuffer.lhs
@@
-6,6
+6,11
@@
Buffers for scanning string input stored in external arrays.
\begin{code}
Buffers for scanning string input stored in external arrays.
\begin{code}
+{-# LANGUAGE BangPatterns #-}
+{-# OPTIONS_GHC -O -funbox-strict-fields #-}
+-- We always optimise this, otherwise performance of a non-optimised
+-- compiler is severely affected
+
module StringBuffer
(
StringBuffer(..),
module StringBuffer
(
StringBuffer(..),
@@
-75,7
+80,7
@@
data StringBuffer
instance Show StringBuffer where
showsPrec _ s = showString "<stringbuffer("
. shows (len s) . showString "," . shows (cur s)
instance Show StringBuffer where
showsPrec _ s = showString "<stringbuffer("
. shows (len s) . showString "," . shows (cur s)
- . showString ">"
+ . showString ")>"
-- -----------------------------------------------------------------------------
-- Creation / Destruction
-- -----------------------------------------------------------------------------
-- Creation / Destruction
@@
-134,8
+139,9
@@
appendStringBuffers sb1 sb2
calcLen sb = len sb - cur sb
size = sb1_len + sb2_len
calcLen sb = len sb - cur sb
size = sb1_len + sb2_len
-stringToStringBuffer :: String -> IO StringBuffer
-stringToStringBuffer str = do
+stringToStringBuffer :: String -> StringBuffer
+stringToStringBuffer str =
+ unsafePerformIO $ do
let size = utf8EncodedLength str
buf <- mallocForeignPtrArray (size+3)
withForeignPtr buf $ \ptr -> do
let size = utf8EncodedLength str
buf <- mallocForeignPtrArray (size+3)
withForeignPtr buf $ \ptr -> do
@@
-220,7
+226,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.
--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
byteOff i = cBox (indexWord8OffFastPtrAsFastChar ptr' (iUnbox (cur + i)))
go i x | i == len = x
| otherwise = case byteOff i of