on master help sign in
Reduce duplication

--HG-- extra : histedit_source : 5c5992ee90e54f83ac0e69a40f43bb228b843348

commit7d9d95cf47c6f34a6e4949237a70fb26c5aa37f3 authorBryan O'Sullivan <bos@serpentine.com> dateMon 18 Mar 2013, 22:37 (14 years ago) parent2d089a6
2 files changed+17−14
Data/Text/Lazy/Builder/Int.hs+10−11 Data/Text/Lazy/Builder/Internal.hs+7−3
Data/Text/Lazy/Builder/Int.hs+10−11
@@ -54,12 +54,7 @@ decimal :: Integral a => a -> Builder
5454{-# RULES "decimal/Word32" decimal = positive :: Word32 -> Builder #-}
5555{-# RULES "decimal/Word64" decimal = positive :: Word64 -> Builder #-}
5656{-# RULES "decimal/Integer" decimal = integer 10 :: Integer -> Builder #-}
57−decimal i
58− | i < 0 = singleton '-' <>
59− if i <= -128
60− then positive (-(i `quot` 10)) <> digit (-(i `rem` 10))
61− else positive (-i)
62− | otherwise = positive i
57+decimal i = decimal' (<= -128) i
6358
6459boundedDecimal :: (Integral a, Bounded a) => a -> Builder
6560{-# SPECIALIZE boundedDecimal :: Int -> Builder #-}
@@ -67,11 +62,15 @@ boundedDecimal :: (Integral a, Bounded a) => a -> Builder
6762{-# SPECIALIZE boundedDecimal :: Int16 -> Builder #-}
6863{-# SPECIALIZE boundedDecimal :: Int32 -> Builder #-}
6964{-# SPECIALIZE boundedDecimal :: Int64 -> Builder #-}
70−boundedDecimal i
71− | i < 0 = singleton '-' <>
72− if i == minBound
73− then positive (-(i `quot` 10)) <> digit (-(i `rem` 10))
74− else positive (-i)
65+boundedDecimal i = decimal' (== minBound) i
66+
67+decimal' :: (Integral a) => (a -> Bool) -> a -> Builder
68+{-# INLINE decimal' #-}
69+decimal' p i
70+ | i < 0 = singleton '-' <>
71+ if p i
72+ then positive (-(i `quot` 10)) <> digit (-(i `rem` 10))
73+ else positive (-i)
7574 | otherwise = positive i
7675
7776positive :: (Integral a) => a -> Builder
Data/Text/Lazy/Builder/Internal.hs+7−3
@@ -28,19 +28,23 @@
2828-----------------------------------------------------------------------------
2929
3030module Data.Text.Lazy.Builder.Internal
31− ( -- * The Builder type
31+ ( -- * Public API
32+ -- ** The Builder type
3233 Builder
3334 , toLazyText
3435 , toLazyTextWith
3536
36− -- * Constructing Builders
37+ -- ** Constructing Builders
3738 , singleton
3839 , fromText
3940 , fromLazyText
4041 , fromString
4142
42− -- * Flushing the buffer state
43+ -- ** Flushing the buffer state
4344 , flush
45+
46+ -- * Internal functions
47+ , writeN
4448 ) where
4549
4650import Control.Monad.ST (ST, runST)