diff options
Diffstat (limited to 'compiler/utils/FastString.hs')
-rw-r--r-- | compiler/utils/FastString.hs | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/compiler/utils/FastString.hs b/compiler/utils/FastString.hs index 5869449f86..c53eff1dd1 100644 --- a/compiler/utils/FastString.hs +++ b/compiler/utils/FastString.hs @@ -16,7 +16,7 @@ -- * Generated by 'fsLit'. -- * Turn into 'Outputable.SDoc' with 'Outputable.ftext'. -- --- ['LitString'] +-- ['PtrString'] -- -- * Pointer and size of a Latin-1 encoded string. -- * Practically no operations. @@ -28,7 +28,7 @@ -- * It assumes Latin-1 as the encoding, therefore it cannot represent -- arbitrary Unicode strings. -- --- Use 'LitString' unless you want the facilities of 'FastString'. +-- Use 'PtrString' unless you want the facilities of 'FastString'. module FastString ( -- * ByteString @@ -79,19 +79,19 @@ module FastString getFastStringTable, hasZEncoding, - -- * LitStrings - LitString (..), + -- * PtrStrings + PtrString (..), -- ** Construction sLit, - mkLitString#, - mkLitString, + mkPtrString#, + mkPtrString, -- ** Deconstruction - unpackLitString, + unpackPtrString, -- ** Operations - lengthLS + lengthPS ) where #include "HsVersions.h" @@ -627,21 +627,21 @@ hPutFS handle fs = BS.hPut handle $ fastStringToByteString fs -- in the current locale's encoding (for error messages and suchlike). -- ----------------------------------------------------------------------------- --- LitStrings, here for convenience only. +-- PtrStrings, here for convenience only. --- | A 'LitString' is a pointer to some array of Latin-1 encoded chars. -data LitString = LitString !(Ptr Word8) !Int +-- | A 'PtrString' is a pointer to some array of Latin-1 encoded chars. +data PtrString = PtrString !(Ptr Word8) !Int --- | Wrap an unboxed address into a 'LitString'. -mkLitString# :: Addr# -> LitString -mkLitString# a# = LitString (Ptr a#) (ptrStrLength (Ptr a#)) +-- | Wrap an unboxed address into a 'PtrString'. +mkPtrString# :: Addr# -> PtrString +mkPtrString# a# = PtrString (Ptr a#) (ptrStrLength (Ptr a#)) --- | Encode a 'String' into a newly allocated 'LitString' using Latin-1 +-- | Encode a 'String' into a newly allocated 'PtrString' using Latin-1 -- encoding. The original string must not contain non-Latin-1 characters -- (above codepoint @0xff@). -{-# INLINE mkLitString #-} -mkLitString :: String -> LitString -mkLitString s = +{-# INLINE mkPtrString #-} +mkPtrString :: String -> PtrString +mkPtrString s = -- we don't use `unsafeDupablePerformIO` here to avoid potential memory leaks -- and because someone might be using `eqAddr#` to check for string equality. unsafePerformIO (do @@ -654,17 +654,17 @@ mkLitString s = pokeByteOff p n (fromIntegral (ord c) :: Word8) loop (1+n) cs loop 0 s - return (LitString p len) + return (PtrString p len) ) --- | Decode a 'LitString' back into a 'String' using Latin-1 encoding. --- This does not free the memory associated with 'LitString'. -unpackLitString :: LitString -> String -unpackLitString (LitString (Ptr p#) (I# n#)) = unpackNBytes# p# n# +-- | Decode a 'PtrString' back into a 'String' using Latin-1 encoding. +-- This does not free the memory associated with 'PtrString'. +unpackPtrString :: PtrString -> String +unpackPtrString (PtrString (Ptr p#) (I# n#)) = unpackNBytes# p# n# --- | Return the length of a 'LitString' -lengthLS :: LitString -> Int -lengthLS (LitString _ n) = n +-- | Return the length of a 'PtrString' +lengthPS :: PtrString -> Int +lengthPS (PtrString _ n) = n -- ----------------------------------------------------------------------------- -- under the carpet @@ -673,14 +673,14 @@ foreign import ccall unsafe "strlen" ptrStrLength :: Ptr Word8 -> Int {-# NOINLINE sLit #-} -sLit :: String -> LitString -sLit x = mkLitString x +sLit :: String -> PtrString +sLit x = mkPtrString x {-# NOINLINE fsLit #-} fsLit :: String -> FastString fsLit x = mkFastString x {-# RULES "slit" - forall x . sLit (unpackCString# x) = mkLitString# x #-} + forall x . sLit (unpackCString# x) = mkPtrString# x #-} {-# RULES "fslit" forall x . fsLit (unpackCString# x) = mkFastString# x #-} |