on master help sign in
Reduce inlining bloat from use of empty literals
commit6d75e1abee09387d752343267e7a2d677534593a authorBryan O'Sullivan <bos@serpentine.com> dateFri 15 Aug 2014, 10:14 (12 years ago) parent74e4526
3 files changed+15−1
Data/Text.hs+5−1 Data/Text/Internal.hs+6 Data/Text/Lazy.hs+4
Data/Text.hs+5−1
@@ -217,7 +217,7 @@ import qualified Data.Text.Internal.Fusion as S
217217import qualified Data.Text.Internal.Fusion.Common as S
218218import Data.Text.Internal.Fusion (stream, reverseStream, unstream)
219219import Data.Text.Internal.Private (span_)
220−import Data.Text.Internal (Text(..), empty, firstf, mul, safe, text)
220+import Data.Text.Internal (Text(..), empty, empty_, firstf, mul, safe, text)
221221import qualified Prelude as P
222222import Data.Text.Unsafe (Iter(..), iter, iter_, lengthWord16, reverseIter,
223223 reverseIter_, unsafeHead, unsafeTail)
@@ -419,6 +419,10 @@ unpackCString# addr# = unstream (S.streamCString# addr#)
419419 unstream (S.map safe (S.streamList (GHC.unpackCStringUtf8# a)))
420420 = unpackCString# a #-}
421421
422+{-# RULES "TEXT empty literal"
423+ unstream (S.map safe (S.streamList []))
424+ = empty_ #-}
425+
422426-- | /O(1)/ Convert a character into a Text. Subject to fusion.
423427-- Performs replacement on invalid scalar values.
424428singleton :: Char -> Text
Data/Text/Internal.hs+6
@@ -36,6 +36,7 @@ module Data.Text.Internal
3636 , safe
3737 -- * Code that must be here for accessibility
3838 , empty
39+ , empty_
3940 -- * Utilities
4041 , firstf
4142 -- * Checked multiplication
@@ -81,6 +82,11 @@ empty :: Text
8182empty = Text A.empty 0 0
8283{-# INLINE [1] empty #-}
8384
85+-- | A non-inlined version of 'empty'.
86+empty_ :: Text
87+empty_ = Text A.empty 0 0
88+{-# NOINLINE empty_ #-}
89+
8490-- | Construct a 'Text' without invisibly pinning its byte array in
8591-- memory if its length has dwindled to zero.
8692text :: A.Array -> Int -> Int -> Text
Data/Text/Lazy.hs+4
@@ -381,6 +381,10 @@ unpackCString# addr# = unstream (S.streamCString# addr#)
381381 unstream (S.streamList (L.map safe (GHC.unpackCStringUtf8# a)))
382382 = unpackCString# a #-}
383383
384+{-# RULES "LAZY TEXT empty literal"
385+ unstream (S.streamList (L.map safe []))
386+ = Empty #-}
387+
384388-- | /O(1)/ Convert a character into a Text. Subject to fusion.
385389-- Performs replacement on invalid scalar values.
386390singleton :: Char -> Text