@@ -8,6 +8,8 @@
88#endif
99#ifdef __GHCJS__
1010{-# LANGUAGE ForeignFunctionInterface #-}
11+{-# LANGUAGE MagicHash #-}
12+{-# LANGUAGE UnliftedFFITypes #-}
1113#endif
1214-- |
1315-- Module : Data.Text.Lazy
@@ -248,6 +250,8 @@ import Text.Printf (PrintfArg, formatArg, formatString)
248250#endif
249251#ifdef __GHCJS__
250252import Data.JSString (JSString)
253+import GHC.Base (Int(..))
254+import GHC.Exts (Int#)
251255#endif
252256
253257-- $fusion
@@ -353,8 +357,8 @@ compareText (Chunk a0 as) (Chunk b0 bs) = outer a0 b0
353357 | otherwise = go (i+di) (j+dj)
354358 where T.Iter a di = T.iter ta i
355359 T.Iter b dj = T.iter tb j
356− lenA = T.length ta
357− lenB = T.length tb
360+ lenA = I# (js_length jsa)
361+ lenB = I# (js_length jsb)
358362#endif
359363
360364instance Show Text where
@@ -1181,7 +1185,7 @@ dropWords i t0
11811185 | n < len' = chunk (T.Text $ js_substr1 n' jst) ts
11821186 | otherwise = drop' (n - len') ts
11831187 where len' = fromIntegral len
1184− len = T.length t
1188+ len = I# (js_length jst)
11851189 n' = fromIntegral n
11861190#endif
11871191
@@ -1321,7 +1325,7 @@ splitAtWord x (Chunk c@(T.Text jst) cs)
13211325 | otherwise = chunk (T.Text (js_substr 0 (y-1) jst)) empty :*:
13221326 chunk (T.Text (js_substr1 y jst)) cs
13231327 where y = fromIntegral x
1324− len = T.length c
1328+ len = I# (js_length jst)
13251329#endif
13261330
13271331-- | /O(n+m)/ Find the first instance of @needle@ (which must be
@@ -1505,7 +1509,7 @@ splitOn pat src
15051509#ifndef __GHCJS__
15061510 l = foldlChunks (\a (T.Text _ _ b) -> a + fromIntegral b) 0 pat
15071511#else
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
15091513#endif
15101514{-# INLINE [1] splitOn #-}
15111515
@@ -1774,4 +1778,5 @@ impossibleError fun = P.error ("Data.Text.Lazy." ++ fun ++ ": impossible case")
17741778#ifdef __GHCJS__
17751779foreign import javascript unsafe "$2.substr($1)" js_substr1 :: Exts.Int -> JSString -> JSString
17761780foreign 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#
17771782#endif