@@ -64,6 +64,7 @@ import Data.ByteString as B
64import Data.ByteString.Internal as B
64import Data.ByteString.Internal as B
65import Data.ByteString.Lazy.Builder.Internal as B
65import Data.ByteString.Lazy.Builder.Internal as B
66import qualified Data.ByteString.Lazy.Builder.BasicEncoding.Internal as B
66import qualified Data.ByteString.Lazy.Builder.BasicEncoding.Internal as B
67+import qualified Data.ByteString.Lazy.Builder.BasicEncoding as B
67import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
68import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
68import Data.Text.Internal (Text(..), textP)
69import Data.Text.Internal (Text(..), textP)
69import Data.Text.UnsafeChar (ord, unsafeWrite)
70import Data.Text.UnsafeChar (ord, unsafeWrite)
@@ -315,50 +316,7 @@ encodeTextWithB be = encodeStreamWithB be . F.stream
316-- | Encode text using UTF-8 encoding.
317-- | Encode text using UTF-8 encoding.
317encodeUtf8Builder :: Text -> B.Builder
318encodeUtf8Builder :: Text -> B.Builder
318−encodeUtf8Builder (Text arr off len) =
319+encodeUtf8Builder = encodeUtf8Escaped (B.fromF B.word8)
326− outerLoop !i0 !br@(BufferRange op0 ope)
328− | op0 `plusPtr` bound < ope =
329− goPartial (i0 + min outRemaining inpRemaining)
330− | otherwise = return $ bufferFull bound op0 (outerLoop i0)
332− outRemaining = (ope `minusPtr` op0) `div` bound
333− inpRemaining = iend - i0
335− goPartial !iendTmp = go i0 op0
338− | i < iendTmp = case A.unsafeIndex arr i of
341− go (i + 1) (op `plusPtr` 1)
343− poke8 0 $ (w `shiftR` 6) + 0xC0
344− poke8 1 $ (w .&. 0x3f) + 0x80
345− go (i + 1) (op `plusPtr` 2)
346− | 0xD800 <= w && w <= 0xDBFF -> do
347− let c = ord $ U16.chr2 w (A.unsafeIndex arr (i+1))
348− poke8 0 $ (c `shiftR` 18) + 0xF0
349− poke8 1 $ ((c `shiftR` 12) .&. 0x3F) + 0x80
350− poke8 2 $ ((c `shiftR` 6) .&. 0x3F) + 0x80
351− poke8 3 $ (c .&. 0x3F) + 0x80
352− go (i + 2) (op `plusPtr` 4)
354− poke8 0 $ (w `shiftR` 12) + 0xE0
355− poke8 1 $ ((w `shiftR` 6) .&. 0x3F) + 0x80
356− poke8 2 $ (w .&. 0x3F) + 0x80
357− go (i + 1) (op `plusPtr` 3)
359− outerLoop i (BufferRange op ope)
361− poke8 j v = poke (op `plusPtr` j) (fromIntegral v :: Word8)
363-- | Encode text using UTF-8 encoding and escape the ASCII characters using
321-- | Encode text using UTF-8 encoding and escape the ASCII characters using
364-- a 'BoundedEncoding'.
322-- a 'BoundedEncoding'.