@@ -34,11 +34,11 @@ import Control.Exception (assert)
3434#endif
3535import Control.Monad.ST (ST, runST)
3636import Data.Bits ((.&.))
37−import Data.Char (ord)
3837import Data.Monoid (Monoid(..))
3938import Data.Text.Internal (Text(..))
4039import Data.Text.Lazy.Internal (smallChunkSize)
4140import Data.Text.Unsafe (inlineInterleaveST)
41+import Data.Text.UnsafeChar (ord, unsafeWrite)
4242import Data.Text.UnsafeShift (shiftR)
4343import Prelude hiding (map, putChar)
4444
@@ -258,29 +258,6 @@ newBuffer size = do
258258 return $! Buffer arr 0 0 size
259259{-# INLINE newBuffer #-}
260260
261−-- Write a character to the array, starting at the specified offset
262−-- @i@. Returns the number of elements written.
263−unsafeWrite :: A.MArray s -> Int -> Char -> ST s Int
264−unsafeWrite marr i c
265− | n < 0x10000 = do
266−#if defined(ASSERTS)
267− assert (i >= 0) . assert (i < A.length marr) $ return ()
268−#endif
269− A.unsafeWrite marr i (fromIntegral n)
270− return 1
271− | otherwise = do
272−#if defined(ASSERTS)
273− assert (i >= 0) . assert (i < A.length marr - 1) $ return ()
274−#endif
275− A.unsafeWrite marr i lo
276− A.unsafeWrite marr (i+1) hi
277− return 2
278− where n = ord c
279− m = n - 0x10000
280− lo = fromIntegral $ (m `shiftR` 10) + 0xD800
281− hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
282−{-# INLINE unsafeWrite #-}
283−
284261------------------------------------------------------------------------
285262-- Some nice rules for Builder
286263