@@ -8,6 +8,8 @@
9#ifdef __GHCJS__
9#ifdef __GHCJS__
10{-# LANGUAGE ForeignFunctionInterface #-}
10{-# LANGUAGE ForeignFunctionInterface #-}
11+{-# LANGUAGE MagicHash #-}
12+{-# LANGUAGE UnliftedFFITypes #-}
13-- Module : Data.Text.Lazy
15-- Module : Data.Text.Lazy
@@ -248,6 +250,8 @@ import Text.Printf (PrintfArg, formatArg, formatString)
249#ifdef __GHCJS__
251#ifdef __GHCJS__
250import Data.JSString (JSString)
252import Data.JSString (JSString)
253+import GHC.Base (Int(..))
254+import GHC.Exts (Int#)
253-- $fusion
257-- $fusion
@@ -353,8 +357,8 @@ compareText (Chunk a0 as) (Chunk b0 bs) = outer a0 b0
353 | otherwise = go (i+di) (j+dj)
357 | otherwise = go (i+di) (j+dj)
354 where T.Iter a di = T.iter ta i
358 where T.Iter a di = T.iter ta i
355 T.Iter b dj = T.iter tb j
359 T.Iter b dj = T.iter tb j
356− lenA = T.length ta
360+ lenA = I# (js_length jsa)
357− lenB = T.length tb
361+ lenB = I# (js_length jsb)
360instance Show Text where
364instance Show Text where
@@ -1181,7 +1185,7 @@ dropWords i t0
1181 | n < len' = chunk (T.Text $ js_substr1 n' jst) ts
1185 | n < len' = chunk (T.Text $ js_substr1 n' jst) ts
1182 | otherwise = drop' (n - len') ts
1186 | otherwise = drop' (n - len') ts
1183 where len' = fromIntegral len
1187 where len' = fromIntegral len
1184− len = T.length t
1188+ len = I# (js_length jst)
1185 n' = fromIntegral n
1189 n' = fromIntegral n
@@ -1321,7 +1325,7 @@ splitAtWord x (Chunk c@(T.Text jst) cs)
1321 | otherwise = chunk (T.Text (js_substr 0 (y-1) jst)) empty :*:
1325 | otherwise = chunk (T.Text (js_substr 0 (y-1) jst)) empty :*:
1322 chunk (T.Text (js_substr1 y jst)) cs
1326 chunk (T.Text (js_substr1 y jst)) cs
1323 where y = fromIntegral x
1327 where y = fromIntegral x
1324− len = T.length c
1328+ len = I# (js_length jst)
1327-- | /O(n+m)/ Find the first instance of @needle@ (which must be
1331-- | /O(n+m)/ Find the first instance of @needle@ (which must be
@@ -1505,7 +1509,7 @@ splitOn pat src
1505#ifndef __GHCJS__
1509#ifndef __GHCJS__
1506 l = foldlChunks (\a (T.Text _ _ b) -> a + fromIntegral b) 0 pat
1510 l = foldlChunks (\a (T.Text _ _ b) -> a + fromIntegral b) 0 pat
1508− l = foldlChunks (\a t -> a + fromIntegral (T.length t)) 0 pat
1512+ l = foldlChunks (\a (T.Text t) -> a + fromIntegral (I# (js_length t))) 0 pat
1510{-# INLINE [1] splitOn #-}
1514{-# INLINE [1] splitOn #-}
@@ -1774,4 +1778,5 @@ impossibleError fun = P.error ("Data.Text.Lazy." ++ fun ++ ": impossible case")
1774#ifdef __GHCJS__
1778#ifdef __GHCJS__
1775foreign import javascript unsafe "$2.substr($1)" js_substr1 :: Exts.Int -> JSString -> JSString
1779foreign import javascript unsafe "$2.substr($1)" js_substr1 :: Exts.Int -> JSString -> JSString
1776foreign import javascript unsafe "$3.substr($1,$2)" js_substr :: Exts.Int -> Exts.Int -> JSString -> JSString
1780foreign import javascript unsafe "$3.substr($1,$2)" js_substr :: Exts.Int -> Exts.Int -> JSString -> JSString
1781+foreign import javascript unsafe "$1.length" js_length :: JSString -> Int#