on master help sign in
Float ensureFree way out
1918c8cBryan O'Sullivan
Data/Text/Lazy/Builder/Int.hs+11−6
@@ -18,7 +18,7 @@ module Data.Text.Lazy.Builder.Int
18import Data.Int (Int8, Int16, Int32, Int64)
18import Data.Int (Int8, Int16, Int32, Int64)
19import Data.Monoid (mempty)
19import Data.Monoid (mempty)
20import Data.Text.Lazy.Builder.Functions ((<>), i2d)
20import Data.Text.Lazy.Builder.Functions ((<>), i2d)
21−import Data.Text.Lazy.Builder
21+import Data.Text.Lazy.Builder.Internal
22import Data.Word (Word, Word8, Word16, Word32, Word64)
22import Data.Word (Word, Word8, Word16, Word32, Word64)
23import GHC.Base (quotInt, remInt)
23import GHC.Base (quotInt, remInt)
24import GHC.Num (quotRemInteger)
24import GHC.Num (quotRemInteger)
@@ -67,11 +67,16 @@ boundedDecimal i = decimal' (== minBound) i
67decimal' :: (Integral a) => (a -> Bool) -> a -> Builder
67decimal' :: (Integral a) => (a -> Bool) -> a -> Builder
68{-# INLINE decimal' #-}
68{-# INLINE decimal' #-}
69decimal' p i
69decimal' p i
70− | i < 0 = singleton '-' <>
71− if p i
70+ | i < 0 = if p i
72− then positive (-(i `quot` 10)) <> digit (-(i `rem` 10))
71+ then let j = -(i `quot` 10)
72+ n = countDigits j + 2
73+ in go n $ singleton '-' <>
74+ positive j <> digit (-(i `rem` 10))
73− else positive (-i)
75+ else let j = -i
76+ n = countDigits j + 1
77+ in go n $ singleton '-' <> positive j
74− | otherwise = positive i
78+ | otherwise = go (countDigits i) $ positive i
79+ where go k b = ensureFree k `append'` b
75
80
76positive :: (Integral a) => a -> Builder
81positive :: (Integral a) => a -> Builder
77{-# SPECIALIZE positive :: Int -> Builder #-}
82{-# SPECIALIZE positive :: Int -> Builder #-}
Data/Text/Lazy/Builder/Internal.hs+2−1
@@ -44,7 +44,8 @@ module Data.Text.Lazy.Builder.Internal
44 , flush
44 , flush
45
45
46 -- * Internal functions
46 -- * Internal functions
47− , writeN
47+ , append'
48+ , ensureFree
48 ) where
49 ) where
49
50
50import Control.Monad.ST (ST, runST)
51import Control.Monad.ST (ST, runST)