Gives the Modified UTF-8 encoded bytes corresponding to a FastString
Moduleghc-9.10.3GHC2021
GHC.Data.FastString
There are two principal string types used internally by GHC:
A compact, hash-consed, representation of character strings.
Generated by fsLit.
You can get a Unique from them.
Equality test is O(1) (it uses the Unique).
Comparison is O(1) or O(n):
O(n) but deterministic with lexical comparison (lexicalCompareFS)
O(1) but non-deterministic with Unique comparison (uniqCompareFS)
Pointer and size of a Latin-1 encoded string.
Practically no operations.
Outputting them is fast.
Generated by mkPtrString#.
Length of string literals (mkPtrString# "abc"#) is computed statically
Requires manual memory management. Improper use may lead to memory leaks or dangling pointers.
It assumes Latin-1 as the encoding, therefore it cannot represent arbitrary Unicode strings.
Use PtrString unless you want the facilities of FastString.
- 5 types
- 36 values
- Packageghc-9.10.3
- Exports41
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceFastString.hs
ByteString
5 declarationsDeprecated. Use bytesFS instead
Gives the Modified UTF-8 encoded bytes corresponding to a FastString
Create a FastString by copying an existing ByteString
ShortByteString
2 declarationsCreate a FastString from an existing ShortByteString without copying.
ShortText
1 declarationFastZString
5 declarationsInstances1NFData
NFData FastZStringDefined in ghc-9.10.3 · GHC.Data.FastString
zStringTakeN n = take n . zString
but is performed in O(\min(n,l)) rather than O(l),
where l is the length of the FastZString.
FastStrings
3 declarationsA FastString is a UTF-8 encoded string together with a unique ID. All FastStrings are stored in a global hashtable to support fast O(1) comparison.
It is also associated with a lazy reference to the Z-encoding of this string which is used by the compiler internally.
Constructors
FastStringuniq :: !Intn_chars :: !Intfs_sbs :: !ShortByteStringfs_zenc :: FastZStringLazily computed Z-encoding of this string. See Note [Z-Encoding] in GHC.Utils.Encoding.
Since FastStrings are globally memoized this is computed at most once for any given string.
Instances14Eq, Data, Show, IsString, Semigroup, Monoid, …
Eq FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringData FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringShow FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringIsString FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringSemigroup FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringMonoid FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringNFData FastStringDefined in ghc-9.10.3 · GHC.Data.FastStringOutputable FastStringDefined in ghc-9.10.3 · GHC.Utils.OutputableUniquable FastStringDefined in ghc-9.10.3 · GHC.Types.UniqueBinary FastStringDefined in ghc-9.10.3 · GHC.Utils.BinaryToJExpr FastStringDefined in ghc-9.10.3 · GHC.JS.MakeToJExpr a => ToJExpr (UniqMap FastString a)Defined in ghc-9.10.3 · GHC.JS.Maketype Anno FastString = EpAnnCODefined in ghc-9.10.3 · GHC.Hs.Expr · orphantype Anno (SourceText, RuleName) = EpAnnCODefined in ghc-9.10.3 · GHC.Hs.Decls · orphan
Non-deterministic FastString
This is a simple FastString wrapper with an Ord instance using uniqCompareFS (i.e. which compares FastStrings on their Uniques). Hence it is not deterministic from one run to the other.
Constructors
Instances6Eq, Data, Ord, Show, Outputable, Binary
Eq NonDetFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringData NonDetFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringOrd NonDetFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringShow NonDetFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringOutputable NonDetFastStringDefined in ghc-9.10.3 · GHC.Utils.OutputableBinary NonDetFastStringDefined in ghc-9.10.3 · GHC.Utils.Binary
Lexical FastString
This is a simple FastString wrapper with an Ord instance using lexicalCompareFS (i.e. which compares FastStrings on their String representation). Hence it is deterministic from one run to the other.
Constructors
Instances6Eq, Data, Ord, Show, Outputable, Binary
Eq LexicalFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringData LexicalFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringOrd LexicalFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringShow LexicalFastStringDefined in ghc-9.10.3 · GHC.Data.FastStringOutputable LexicalFastStringDefined in ghc-9.10.3 · GHC.Utils.OutputableBinary LexicalFastStringDefined in ghc-9.10.3 · GHC.Utils.Binary
Construction
Creates a UTF-8 encoded FastString from a String
Creates a FastString from a UTF-8 encoded [Word8]
Deconstruction
Lazily unpacks and decodes the FastString
Encoding
Returns a Z-encoded version of a FastString. This might be the original, if it was already Z-encoded. The first time this function is applied to a particular FastString, the results are memoized.
Operations
Returns the length of the FastString in characters
Returns True if the FastString is empty
Compare FastString lexically
If you don't care about the lexical ordering, use uniqCompareFS instead.
Compare FastString by their Unique (not lexically).
Much cheaper than lexicalCompareFS but non-deterministic!
Outputting
Outputs a FastString with no decoding at all, that is, you get the actual bytes in the FastString written to the Handle.
Internal
PtrStrings
1 declarationConstruction
Wrap an unboxed address into a PtrString.
Deconstruction
unpackPtrStringTakeN n = take n . unpackPtrString
but is performed in O(\min(n,l)) rather than O(l),
where l is the length of the PtrString.
Operations
Return the length of a PtrString