on master help sign in
Various fixes for Data.Text.Lazy and *word16
f7ba53cLuigy Leon
Data/Text/Internal/Fusion.hs+1−1
@@ -84,7 +84,7 @@ unstream = coerce JSS.unstream
84{-# RULES "STREAM stream/unstream fusion" forall s. stream (unstream s) = s #-}
84{-# RULES "STREAM stream/unstream fusion" forall s. stream (unstream s) = s #-}
85
85
86length :: Stream Char -> Int
86length :: Stream Char -> Int
87−length = JSS.length
87+length = S.lengthI
88{-# INLINE [0] length #-}
88{-# INLINE [0] length #-}
89
89
90reverse :: Stream Char -> Text
90reverse :: Stream Char -> Text
Data/Text/Internal/Lazy/Fusion.hs+6−2
@@ -63,17 +63,21 @@ stream text = Stream next (text :*: 0) unknownSize
63 | i >= len = next (ts :*: 0)
63 | i >= len = next (ts :*: 0)
64 | otherwise = Yield c (txt :*: i+d)
64 | otherwise = Yield c (txt :*: i+d)
65 where Iter c d = iter t i
65 where Iter c d = iter t i
66+{-# INLINE [0] stream #-}
66#else
67#else
67stream text = Stream next (text :*: 0) -- unknownSize
68stream text = Stream next (text :*: 0) -- unknownSize
68 where
69 where
69 next (Empty :*: _) = Done
70 next (Empty :*: _) = Done
70 next (txt@(Chunk t@(I.Text jst) ts) :*: i)
71 next (txt@(Chunk t@(I.Text jst) ts) :*: i)
71− | i >= JSS.length jst = next (ts :*: 0)
72+ | i >= I# (js_length jst) = next (ts :*: 0)
72 | otherwise = Yield c (txt :*: i+d)
73 | otherwise = Yield c (txt :*: i+d)
73 where Iter c d = iter t i
74 where Iter c d = iter t i
74−#endif
75{-# INLINE [0] stream #-}
75{-# INLINE [0] stream #-}
76
76
77+foreign import javascript unsafe
78+ "$1.length" js_length :: JSString -> Int#
79+#endif
80+
77-- TODO
81-- TODO
78-- | /O(n)/ Convert a 'Stream Char' into a 'Text', using the given
82-- | /O(n)/ Convert a 'Stream Char' into a 'Text', using the given
79-- chunk size.
83-- chunk size.
Data/Text/Lazy.hs+10−5
@@ -8,6 +8,8 @@
8#endif
8#endif
9#ifdef __GHCJS__
9#ifdef __GHCJS__
10{-# LANGUAGE ForeignFunctionInterface #-}
10{-# LANGUAGE ForeignFunctionInterface #-}
11+{-# LANGUAGE MagicHash #-}
12+{-# LANGUAGE UnliftedFFITypes #-}
11#endif
13#endif
12-- |
14-- |
13-- Module : Data.Text.Lazy
15-- Module : Data.Text.Lazy
@@ -248,6 +250,8 @@ import Text.Printf (PrintfArg, formatArg, formatString)
248#endif
250#endif
249#ifdef __GHCJS__
251#ifdef __GHCJS__
250import Data.JSString (JSString)
252import Data.JSString (JSString)
253+import GHC.Base (Int(..))
254+import GHC.Exts (Int#)
251#endif
255#endif
252
256
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)
358#endif
362#endif
359
363
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
1186#endif
1190#endif
1187
1191
@@ -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)
1325#endif
1329#endif
1326
1330
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
1507#else
1511#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
1509#endif
1513#endif
1510{-# INLINE [1] splitOn #-}
1514{-# INLINE [1] splitOn #-}
1511
1515
@@ -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#
1777#endif
1782#endif
Data/Text/Unsafe.hs+6−5
@@ -183,7 +183,7 @@ takeWord16 :: Int -> Text -> Text
183#ifndef __GHCJS__
183#ifndef __GHCJS__
184takeWord16 k (Text arr off _len) = Text arr off k
184takeWord16 k (Text arr off _len) = Text arr off k
185#else
185#else
186−takeWord16 k (Text txt) = Text $ js_take k txt
186+takeWord16 (I# k) (Text txt) = Text $ js_substr 0# k txt
187#endif
187#endif
188{-# INLINE takeWord16 #-}
188{-# INLINE takeWord16 #-}
189
189
@@ -192,7 +192,7 @@ dropWord16 :: Int -> Text -> Text
192#ifndef __GHCJS__
192#ifndef __GHCJS__
193dropWord16 k (Text arr off len) = Text arr (off+k) (len-k)
193dropWord16 k (Text arr off len) = Text arr (off+k) (len-k)
194#else
194#else
195−dropWord16 k (Text txt) = Text $ js_drop k txt
195+dropWord16 (I# k) (Text txt) = Text $ js_substr1 k txt
196#endif
196#endif
197{-# INLINE dropWord16 #-}
197{-# INLINE dropWord16 #-}
198
198
@@ -201,11 +201,12 @@ foreign import javascript unsafe
201 "$2.charCodeAt($1)" js_charCodeAt :: Int -> JSString -> Int#
201 "$2.charCodeAt($1)" js_charCodeAt :: Int -> JSString -> Int#
202
202
203foreign import javascript unsafe
203foreign import javascript unsafe
204− "h$jsstringTake" js_take :: Int -> JSString -> JSString
204+ "$1.length" js_length :: JSString -> Int
205
205
206foreign import javascript unsafe
206foreign import javascript unsafe
207− "h$jsstringDrop" js_drop :: Int -> JSString -> JSString
207+ "$3.substr($1,$2)" js_substr :: Int# -> Int# -> JSString -> JSString
208
208
209foreign import javascript unsafe
209foreign import javascript unsafe
210− "$1.length" js_length :: JSString -> Int
210+ "$2.substr($1)" js_substr1 :: Int# -> JSString -> JSString
211+
211#endif
212#endif