on master help sign in
Float ensureFree way out

--HG-- extra : amend_source : 92cd186bb054e54ad3f8d4a1defe55c2dfdbe98e extra : histedit_source : 70465aa0273f6e0cee5d628f65660026e4ea6f52

commit1918c8ceaf9fb6d7e739f70b97c7c468c034fce1 authorBryan O'Sullivan <bos@serpentine.com> dateMon 18 Mar 2013, 22:55 (14 years ago) parent7d9d95c
2 files changed+13−7
Data/Text/Lazy/Builder/Int.hs+11−6 Data/Text/Lazy/Builder/Internal.hs+2−1
Data/Text/Lazy/Builder/Int.hs+11−6
@@ -18,7 +18,7 @@ module Data.Text.Lazy.Builder.Int
1818import Data.Int (Int8, Int16, Int32, Int64)
1919import Data.Monoid (mempty)
2020import Data.Text.Lazy.Builder.Functions ((<>), i2d)
21−import Data.Text.Lazy.Builder
21+import Data.Text.Lazy.Builder.Internal
2222import Data.Word (Word, Word8, Word16, Word32, Word64)
2323import GHC.Base (quotInt, remInt)
2424import GHC.Num (quotRemInteger)
@@ -67,11 +67,16 @@ boundedDecimal i = decimal' (== minBound) i
6767decimal' :: (Integral a) => (a -> Bool) -> a -> Builder
6868{-# INLINE decimal' #-}
6969decimal' p i
70− | i < 0 = singleton '-' <>
71− if p i
72− then positive (-(i `quot` 10)) <> digit (-(i `rem` 10))
73− else positive (-i)
74− | otherwise = positive i
70+ | i < 0 = if p i
71+ then let j = -(i `quot` 10)
72+ n = countDigits j + 2
73+ in go n $ singleton '-' <>
74+ positive j <> digit (-(i `rem` 10))
75+ else let j = -i
76+ n = countDigits j + 1
77+ in go n $ singleton '-' <> positive j
78+ | otherwise = go (countDigits i) $ positive i
79+ where go k b = ensureFree k `append'` b
7580
7681positive :: (Integral a) => a -> Builder
7782{-# SPECIALIZE positive :: Int -> Builder #-}
Data/Text/Lazy/Builder/Internal.hs+2−1
@@ -44,7 +44,8 @@ module Data.Text.Lazy.Builder.Internal
4444 , flush
4545
4646 -- * Internal functions
47− , writeN
47+ , append'
48+ , ensureFree
4849 ) where
4950
5051import Control.Monad.ST (ST, runST)