@@ -431,13 +431,11 @@ encodeUtf8_1 (Text arr off len)
431 let size0 = max len 4
431 let size0 = max len 4
432 mallocByteString size0 >>= start size0 off 0
432 mallocByteString size0 >>= start size0 off 0
434− start size n0 m0 fp = withForeignPtr fp $ loop n0 m0
434+ start size n0 m0 fp = withForeignPtr fp $ go n0 m0
436− loop n1 m1 ptr = go n1 m1
438 offLen = off + len
436 offLen = off + len
439 poke8 p k v = poke (p `plusPtr` k) (fromIntegral v :: Word8)
437 poke8 p k v = poke (p `plusPtr` k) (fromIntegral v :: Word8)
440− go !n !m
438+ go !n !m ptr
441 | n == offLen = return (PS fp 0 m)
439 | n == offLen = return (PS fp 0 m)
442 | otherwise = do
440 | otherwise = do
443 let ensure k act
441 let ensure k act
@@ -452,23 +450,23 @@ encodeUtf8_1 (Text arr off len)
452 case A.unsafeIndex arr n of
450 case A.unsafeIndex arr n of
453 w| w <= 0x7F -> ensure 1 $ do
451 w| w <= 0x7F -> ensure 1 $ do
454 poke8 ptr m (fromIntegral w :: Word8)
452 poke8 ptr m (fromIntegral w :: Word8)
455− go (n+1) (m+1)
453+ go (n+1) (m+1) ptr
456 | w <= 0x7FF -> ensure 2 $ do
454 | w <= 0x7FF -> ensure 2 $ do
457 poke8 ptr m $ (w `shiftR` 6) + 0xC0
455 poke8 ptr m $ (w `shiftR` 6) + 0xC0
458 poke8 ptr (m+1) $ (w .&. 0x3f) + 0x80
456 poke8 ptr (m+1) $ (w .&. 0x3f) + 0x80
459− go (n+1) (m+2)
457+ go (n+1) (m+2) ptr
460 | 0xD800 <= w && w <= 0xDBFF -> ensure 4 $ do
458 | 0xD800 <= w && w <= 0xDBFF -> ensure 4 $ do
461 let c = ord $ U16.chr2 w (A.unsafeIndex arr (n+1))
459 let c = ord $ U16.chr2 w (A.unsafeIndex arr (n+1))
462 poke8 ptr m $ (c `shiftR` 18) + 0xF0
460 poke8 ptr m $ (c `shiftR` 18) + 0xF0
463 poke8 ptr (m+1) $ ((c `shiftR` 12) .&. 0x3F) + 0x80
461 poke8 ptr (m+1) $ ((c `shiftR` 12) .&. 0x3F) + 0x80
464 poke8 ptr (m+2) $ ((c `shiftR` 6) .&. 0x3F) + 0x80
462 poke8 ptr (m+2) $ ((c `shiftR` 6) .&. 0x3F) + 0x80
465 poke8 ptr (m+3) $ (c .&. 0x3F) + 0x80
463 poke8 ptr (m+3) $ (c .&. 0x3F) + 0x80
466− go (n+2) (m+4)
464+ go (n+2) (m+4) ptr
467 | otherwise -> ensure 3 $ do
465 | otherwise -> ensure 3 $ do
468 poke8 ptr m $ (w `shiftR` 12) + 0xE0
466 poke8 ptr m $ (w `shiftR` 12) + 0xE0
469 poke8 ptr (m+1) $ ((w `shiftR` 6) .&. 0x3F) + 0x80
467 poke8 ptr (m+1) $ ((w `shiftR` 6) .&. 0x3F) + 0x80
470 poke8 ptr (m+2) $ (w .&. 0x3F) + 0x80
468 poke8 ptr (m+2) $ (w .&. 0x3F) + 0x80
471− go (n+1) (m+3)
469+ go (n+1) (m+3) ptr