@@ -311,22 +311,8 @@ decodeUtf8' :: ByteString -> Either UnicodeException Text
311decodeUtf8' = unsafeDupablePerformIO . try . evaluate . decodeUtf8With strictDecode
311decodeUtf8' = unsafeDupablePerformIO . try . evaluate . decodeUtf8With strictDecode
312{-# INLINE decodeUtf8' #-}
312{-# INLINE decodeUtf8' #-}
314−-- | Encode text using UTF-8 encoding.
315−encodeUtf8 :: Text -> ByteString
316#if MIN_VERSION_bytestring(0,10,4)
314#if MIN_VERSION_bytestring(0,10,4)
318−encodeUtf8 t@(Text _arr _off len) =
319− B.copy -- copy to trim and avoid wasting memory
321− $ B.toLazyByteStringWith strategy BL.empty
322− $ encodeUtf8Builder t
324− -- We use a strategy that allocates a buffer that is guaranteed to be
325− -- large enough for the whole result. This ensures that we always stay in
326− -- the fast 'goPartial' loop in the 'encodeUtf8BuilderEscaped' function.
327− strategy = B.untrimmedStrategy (4 * (len + 1)) B.defaultChunkSize
330-- | Encode text to a ByteString 'B.Builder' using UTF-8 encoding.
316-- | Encode text to a ByteString 'B.Builder' using UTF-8 encoding.
331encodeUtf8Builder :: Text -> B.Builder
317encodeUtf8Builder :: Text -> B.Builder
332encodeUtf8Builder = encodeUtf8BuilderEscaped (BP.liftFixedToBounded BP.word8)
318encodeUtf8Builder = encodeUtf8BuilderEscaped (BP.liftFixedToBounded BP.word8)
@@ -387,13 +373,12 @@ encodeUtf8BuilderEscaped be =
387 outerLoop i (B.BufferRange op ope)
373 outerLoop i (B.BufferRange op ope)
389 poke8 j v = poke (op `plusPtr` j) (fromIntegral v :: Word8)
375 poke8 j v = poke (op `plusPtr` j) (fromIntegral v :: Word8)
391−#else
378+-- | Encode text using UTF-8 encoding.
392−
379+encodeUtf8 :: Text -> ByteString
393encodeUtf8 = encodeUtf8_0
380encodeUtf8 = encodeUtf8_0
397encodeUtf8_0 :: Text -> ByteString
382encodeUtf8_0 :: Text -> ByteString
398encodeUtf8_0 (Text arr off len) = unsafeDupablePerformIO $ do
383encodeUtf8_0 (Text arr off len) = unsafeDupablePerformIO $ do
399 let size0 = max len 4
384 let size0 = max len 4