X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FFastString.lhs;h=661b89eaf9b35ac459171f692fdc0b3850a95896;hb=22cf766063c99241e5f5fc2175a60fc63f7a36f3;hp=61750aabdb5ed065f37932030804596be4ff2ffc;hpb=affe92132329afa642bc83d74d5b07d14187e968;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/FastString.lhs b/ghc/compiler/utils/FastString.lhs index 61750aa..661b89e 100644 --- a/ghc/compiler/utils/FastString.lhs +++ b/ghc/compiler/utils/FastString.lhs @@ -3,8 +3,18 @@ % \section{Fast strings} -Compact representations of character strings with -unique identifiers (hash-cons'ish). +FastString: A compact, hash-consed, representation of character strings. + Comparison is O(1), and you can get a Unique from them. + Generated by the FSLIT macro + Turn into SDoc with Outputable.ftext + +LitString: Just a wrapper for the Addr# of a C string (Ptr CChar). + Practically no operations + Outputing them is fast + Generated by the SLIT macro + Turn into SDoc with Outputable.ptext + +Use LitString unless you want the facilities of FastString \begin{code} module FastString @@ -106,6 +116,7 @@ instance Eq FastString where a /= b = case cmpFS a b of { LT -> True; EQ -> False; GT -> True } instance Ord FastString where + -- Compares lexicographically, not by unique a <= b = case cmpFS a b of { LT -> True; EQ -> True; GT -> False } a < b = case cmpFS a b of { LT -> True; EQ -> False; GT -> False } a >= b = case cmpFS a b of { LT -> False; EQ -> True; GT -> True } @@ -431,8 +442,10 @@ cmpFS (FastString u1# l1# b1#) (FastString u2# l2# b2#) = else GT )) -foreign import ccall "ghc_memcmp" unsafe +#ifndef __HADDOCK__ +foreign import ccall unsafe "ghc_memcmp" memcmp :: ByteArray# -> ByteArray# -> Int# -> IO Int +#endif -- ----------------------------------------------------------------------------- -- Outputting 'FastString's @@ -497,7 +510,6 @@ hPutFS handle (UnicodeStr _ is) -- LitStrings, here for convenience only. type LitString = Ptr () --- ToDo: make it a Ptr when we don't have to support 4.08 any more mkLitString# :: Addr# -> LitString mkLitString# a# = Ptr a#