Hoogle Search
Within LTS Haskell 24.36 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
base GHC.RTS.Flags Parameters of the cost-center profiler
-
base GHC.RTS.Flags No documentation available.
PushCallStack :: [Char] -> SrcLoc -> CallStack -> CallStackbase GHC.Stack.Types No documentation available.
ParagraphSeparator :: GeneralCategorybase GHC.Unicode Zp: Separator, Paragraph
-
base GHC.Unicode Co: Other, Private Use
-
bytestring Data.ByteString.Builder.Internal A Put action denotes a computation of a value that writes a stream of bytes as a side-effect. Puts are strict in their side-effect; i.e., the stream of bytes will always be written before the computed value is returned. Puts are a generalization of Builders. The typical use case is the implementation of an encoding that might fail (e.g., an interface to the zlib compression library or the conversion from Base64 encoded data to 8-bit data). For a Builder, the only way to handle and report such a failure is ignore it or call error. In contrast, Put actions are expressive enough to allow reporting and handling such a failure in a pure fashion. Put () actions are isomorphic to Builders. The functions putBuilder and fromPut convert between these two types. Where possible, you should use Builders, as sequencing them is slightly cheaper than sequencing Puts because they do not carry around a computed value.
module Data.ByteString.Builder.
Prim This module provides Builder primitives, which are lower level building blocks for constructing Builders. You don't need to go down to this level but it can be slightly faster. Morally, builder primitives are like functions a -> Builder, that is they take a value and encode it as a sequence of bytes, represented as a Builder. Of course their implementation is a bit more specialised. Builder primitives come in two forms: fixed-size and bounded-size.
- Fixed(-size) primitives are builder primitives that always result in a sequence of bytes of a fixed length. That is, the length is independent of the value that is encoded. An example of a fixed size primitive is the big-endian encoding of a Word64, which always results in exactly 8 bytes.
- Bounded(-size) primitives are builder primitives that always result in a sequence of bytes that is no larger than a predetermined bound. That is, the bound is independent of the value that is encoded but the actual length will depend on the value. An example for a bounded primitive is the UTF-8 encoding of a Char, which can be 1,2,3 or 4 bytes long, so the bound is 4 bytes.
import Data.ByteString.Builder as B renderCell :: Cell -> Builder renderCell (StringC cs) = renderString cs renderCell (IntC i) = B.intDec i renderString :: String -> Builder renderString cs = B.charUtf8 '"' <> foldMap escape cs <> B.charUtf8 '"' where escape '\\' = B.charUtf8 '\\' <> B.charUtf8 '\\' escape '\"' = B.charUtf8 '\\' <> B.charUtf8 '\"' escape c = B.charUtf8 c
Efficient encoding of Ints as decimal numbers is performed by intDec. Optimization potential exists for the escaping of Strings. The above implementation has two optimization opportunities. First, the buffer-free checks of the Builders for escaping double quotes and backslashes can be fused. Second, the concatenations performed by foldMap can be eliminated. The following implementation exploits these optimizations.import qualified Data.ByteString.Builder.Prim as P import Data.ByteString.Builder.Prim ( condB, liftFixedToBounded, (>*<), (>$<) ) renderString :: String -> Builder renderString cs = B.charUtf8 '"' <> primMapListBounded escape cs <> B.charUtf8 '"' where escape :: BoundedPrim Char escape = condB (== '\\') (fixed2 ('\\', '\\')) $ condB (== '\"') (fixed2 ('\\', '\"')) $ charUtf8 {-# INLINE fixed2 #-} fixed2 x = liftFixedToBounded $ const x >$< char7 >*< char7
The code should be mostly self-explanatory. The slightly awkward syntax is because the combinators are written such that the size-bound of the resulting BoundedPrim can be computed at compile time. We also explicitly inline the fixed2 primitive, which encodes a fixed tuple of characters, to ensure that the bound computation happens at compile time. When encoding the following list of Strings, the optimized implementation of renderString is two times faster.maxiStrings :: [String] maxiStrings = take 1000 $ cycle ["hello", "\"1\"", "λ-wörld"]
Most of the performance gain stems from using primMapListBounded, which encodes a list of values from left-to-right with a BoundedPrim. It exploits the Builder internals to avoid unnecessary function compositions (i.e., concatenations). In the future, we might expect the compiler to perform the optimizations implemented in primMapListBounded. However, it seems that the code is currently to complicated for the compiler to see through. Therefore, we provide the BoundedPrim escape hatch, which allows data structures to provide very efficient encoding traversals, like primMapListBounded for lists. Note that BoundedPrims are a bit verbose, but quite versatile. Here is an example of a BoundedPrim for combined HTML escaping and UTF-8 encoding. It exploits that the escaped character with the maximal Unicode codepoint is '>'.{-# INLINE charUtf8HtmlEscaped #-} charUtf8HtmlEscaped :: BoundedPrim Char charUtf8HtmlEscaped = condB (> '>' ) charUtf8 $ condB (== '<' ) (fixed4 ('&',('l',('t',';')))) $ -- < condB (== '>' ) (fixed4 ('&',('g',('t',';')))) $ -- > condB (== '&' ) (fixed5 ('&',('a',('m',('p',';'))))) $ -- & condB (== '"' ) (fixed5 ('&',('#',('3',('4',';'))))) $ -- " condB (== '\'') (fixed5 ('&',('#',('3',('9',';'))))) $ -- ' (liftFixedToBounded char7) -- fallback for Chars smaller than '>' where {-# INLINE fixed4 #-} fixed4 x = liftFixedToBounded $ const x >$< char7 >*< char7 >*< char7 >*< char7 {-# INLINE fixed5 #-} fixed5 x = liftFixedToBounded $ const x >$< char7 >*< char7 >*< char7 >*< char7 >*< char7This module currently does not expose functions that require the special properties of fixed-size primitives. They are useful for prefixing Builders with their size or for implementing chunked encodings. We will expose the corresponding functions in future releases of this library.pattern
PS :: ForeignPtr Word8 -> Int -> Int -> ByteStringbytestring Data.ByteString.Internal PS foreignPtr offset length represents a ByteString with data backed by a given foreignPtr, starting at a given offset in bytes and of a specified length. This pattern is used to emulate the legacy ByteString data constructor, so that pre-existing code generally doesn't need to change to benefit from the simplified BS constructor and can continue to function unchanged. Note: Matching with this constructor will always be given a 0 offset, as the base will be manipulated by plusForeignPtr instead.
-
text Data.Text.Internal.Fusion.Types Strict pair.
module Data.Text.Internal.
PrimCompat No documentation available.