Skip to content

Commit 7888599

Browse files
committed
Add Specialize pragmas back in.
1 parent 2ad0e64 commit 7888599

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/Data/BitCode/Writer/Monad.hs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ instance ( Semigroup (f Word8)
139139
go' !n !b !w = (shift w (n-8), b .|. shift w n)
140140
in r
141141

142-
-- {-# SPECIALIZE instance Monoid (Stream Seq a) #-}
143-
-- {-# SPECIALIZE instance Monoid (Stream [] a) #-}
142+
{-# SPECIALIZE instance Semigroup (Stream Seq a) #-}
143+
{-# SPECIALIZE instance Semigroup (Stream [] a) #-}
144144

145145
instance ( Semigroup (f Word8)
146146
, Monoid (f Word8)
@@ -173,20 +173,23 @@ instance ( Semigroup (f Word8)
173173
go' !n !b !w = (shift w (n-8), b .|. shift w n)
174174
in r
175175

176-
176+
{-# SPECIALIZE instance Monoid (Stream Seq a) #-}
177+
{-# SPECIALIZE instance Monoid (Stream [] a) #-}
177178

178179
instance Semigroup (Streams f a) where
179180
lhs <> (Streams _ 0) = lhs
180181
(Streams _ 0) <> rhs = rhs
181182
(Streams ss1 p1) <> (Streams ss2 p2) = Streams (ss1 <> ss2) (p1 + p2)
182-
-- {-# SPECIALIZE instance Monoid (Streams Seq a) #-}
183-
-- {-# SPECIALIZE instance Monoid (Streams [] a) #-}
183+
184+
{-# SPECIALIZE instance Semigroup (Streams Seq a) #-}
185+
{-# SPECIALIZE instance Semigroup (Streams [] a) #-}
184186

185187
instance Monoid (Streams f a) where
186-
lhs `mappend` (Streams _ 0) = lhs
187-
(Streams _ 0) `mappend` rhs = rhs
188-
(Streams ss1 p1) `mappend` (Streams ss2 p2) = Streams (ss1 <> ss2) (p1 + p2)
189188
mempty = Streams mempty 0
189+
mappend = (<>)
190+
191+
{-# SPECIALIZE instance Monoid (Streams Seq a) #-}
192+
{-# SPECIALIZE instance Monoid (Streams [] a) #-}
190193

191194
-- mappend is not cheap here.
192195
type ListStream = Stream [] Word8
@@ -195,12 +198,12 @@ type SeqStreams = Streams Seq Word8
195198
toListStream :: Foldable f => Stream f a -> Stream [] a
196199
toListStream (S w b p) = S (toList w) b p
197200

198-
-- {-# SPECIALIZE toListStream :: Stream Seq a -> Stream [] a #-}
201+
{-# SPECIALIZE toListStream :: Stream Seq a -> Stream [] a #-}
199202

200203
runStreams :: Streams Seq a -> Stream Seq a
201204
runStreams (Streams ss _) = foldl' mappend mempty ss
202205

203-
-- {-# SPECIALIZE runStreams :: Streams Seq a -> Stream Seq a #-}
206+
{-# SPECIALIZE runStreams :: Streams Seq a -> Stream Seq a #-}
204207

205208
data BitstreamState = BitstreamState !SeqStreams !Position
206209

@@ -228,11 +231,11 @@ streams w b p
228231
| p == 0 = mempty
229232
| otherwise = Streams (pure $ S (Seq.fromList . toList $ w) b p) p
230233

231-
-- {-# SPECIALIZE streams :: [Word8] -> Buff -> Position -> SeqStreams #-}
234+
{-# SPECIALIZE streams :: [Word8] -> Buff -> Position -> SeqStreams #-}
232235
bitstream :: Foldable f => f Word8 -> Buff -> Int -> Bitstream ()
233236
bitstream w b p = Bitstream $ modify' $ \(BitstreamState ss p') -> BitstreamState (ss <> streams w b p) (p + p')
234237

235-
--{-# SPECIALIZE bitstream :: [Word8] -> Buff -> Int -> Bitstream () #-}
238+
{-# SPECIALIZE bitstream :: [Word8] -> Buff -> Int -> Bitstream () #-}
236239
-- Monadic Bitstream API
237240

238241
withOffset :: Int -> Bitstream a -> Bitstream a

0 commit comments

Comments
 (0)