on master help sign in
Reduce inlining bloat from use of singleton
74e4526Bryan O'Sullivan
Data/Text.hs+17−1
@@ -221,7 +221,7 @@ import Data.Text.Internal (Text(..), empty, firstf, mul, safe, text)
221import qualified Prelude as P
221import qualified Prelude as P
222import Data.Text.Unsafe (Iter(..), iter, iter_, lengthWord16, reverseIter,
222import Data.Text.Unsafe (Iter(..), iter, iter_, lengthWord16, reverseIter,
223 reverseIter_, unsafeHead, unsafeTail)
223 reverseIter_, unsafeHead, unsafeTail)
224−import Data.Text.Internal.Unsafe.Char (unsafeChr)
224+import Data.Text.Internal.Unsafe.Char (unsafeChr, unsafeWrite)
225import qualified Data.Text.Internal.Functions as F
225import qualified Data.Text.Internal.Functions as F
226import qualified Data.Text.Internal.Encoding.Utf16 as U16
226import qualified Data.Text.Internal.Encoding.Utf16 as U16
227import Data.Text.Internal.Search (indices)
227import Data.Text.Internal.Search (indices)
@@ -425,6 +425,22 @@ singleton :: Char -> Text
425singleton = unstream . S.singleton . safe
425singleton = unstream . S.singleton . safe
426{-# INLINE [1] singleton #-}
426{-# INLINE [1] singleton #-}
427
427
428+{-# RULES "TEXT singleton" forall a.
429+ unstream (S.singleton (safe a))
430+ = singleton_ a #-}
431+
432+-- This is intended to reduce inlining bloat.
433+singleton_ :: Char -> Text
434+singleton_ c = Text (A.run x) 0 len
435+ where x :: ST s (A.MArray s)
436+ x = do arr <- A.new len
437+ _ <- unsafeWrite arr 0 d
438+ return arr
439+ len | d < '\x10000' = 1
440+ | otherwise = 2
441+ d = safe c
442+{-# NOINLINE singleton_ #-}
443+
428-- -----------------------------------------------------------------------------
444-- -----------------------------------------------------------------------------
429-- * Basic functions
445-- * Basic functions
430
446
Data/Text/Internal.hs+1−1
@@ -110,7 +110,7 @@ safe :: Char -> Char
110safe c
110safe c
111 | ord c .&. 0x1ff800 /= 0xd800 = c
111 | ord c .&. 0x1ff800 /= 0xd800 = c
112 | otherwise = '\xfffd'
112 | otherwise = '\xfffd'
113−{-# INLINE safe #-}
113+{-# INLINE [0] safe #-}
114
114
115-- | Apply a function to the first element of an optional pair.
115-- | Apply a function to the first element of an optional pair.
116firstf :: (a -> c) -> Maybe (a,b) -> Maybe (c,b)
116firstf :: (a -> c) -> Maybe (a,b) -> Maybe (c,b)
Data/Text/Internal/Fusion/Common.hs+1−1
@@ -123,7 +123,7 @@ singleton :: Char -> Stream Char
123singleton c = Stream next False 1
123singleton c = Stream next False 1
124 where next False = Yield c True
124 where next False = Yield c True
125 next True = Done
125 next True = Done
126−{-# INLINE singleton #-}
126+{-# INLINE [0] singleton #-}
127
127
128streamList :: [a] -> Stream a
128streamList :: [a] -> Stream a
129{-# INLINE [0] streamList #-}
129{-# INLINE [0] streamList #-}