28
28
29
29
module Data.ByteString.Builder.RealFloat.Internal
30
30
( mask
31
+ , string7
31
32
, toCharsNonNumbersAndZero
32
33
, SpecialStrings (.. )
33
34
, DecimalLength (.. )
@@ -85,9 +86,7 @@ module Data.ByteString.Builder.RealFloat.Internal
85
86
, module Data.ByteString.Builder.RealFloat.TableGenerator
86
87
) where
87
88
88
- import Control.Monad (foldM )
89
89
import Data.Bits (Bits (.. ), FiniteBits (.. ))
90
- import Data.ByteString.Internal (c2w )
91
90
import Data.ByteString.Builder.Internal (Builder )
92
91
import Data.ByteString.Builder.Prim.Internal (BoundedPrim , boundedPrim )
93
92
import Data.ByteString.Builder.RealFloat.TableGenerator
@@ -99,10 +98,9 @@ import Foreign.C.Types
99
98
import GHC.Int (Int (.. ), Int32 (.. ))
100
99
import GHC.IO (IO (.. ), unIO )
101
100
import GHC.Prim
102
- import GHC.Ptr (Ptr (.. ), plusPtr , castPtr )
101
+ import GHC.Ptr (Ptr (.. ), castPtr )
103
102
import GHC.Types (isTrue #)
104
- import GHC.Word (Word8 , Word16 (.. ), Word32 (.. ), Word64 (.. ))
105
- import qualified Foreign.Storable as S (poke )
103
+ import GHC.Word (Word16 (.. ), Word32 (.. ), Word64 (.. ))
106
104
107
105
#include <ghcautoconf.h>
108
106
#include "MachDeps.h"
@@ -234,15 +232,10 @@ instance DecimalLength Word64 where decimalLength = decimalLength17
234
232
maxEncodedLength :: Int
235
233
maxEncodedLength = 32
236
234
237
- -- | Storable.poke a String into a Ptr Word8, converting through c2w
238
- pokeAll :: String -> Ptr Word8 -> IO (Ptr Word8 )
239
- pokeAll s ptr = foldM pokeOne ptr s
240
- where pokeOne p c = S. poke p (c2w c) >> return (p `plusPtr` 1 )
241
-
242
- -- | Unsafe creation of a bounded primitive of String at most length
243
- -- `maxEncodedLength`
244
- boundString :: String -> BoundedPrim ()
245
- boundString s = boundedPrim maxEncodedLength $ const (pokeAll s)
235
+ -- | Char7 encode a 'String'.
236
+ {-# INLINE string7 #-}
237
+ string7 :: String -> Builder
238
+ string7 = BP. primMapListFixed BP. char7
246
239
247
240
-- | Special rendering for NaN, positive\/negative 0, and positive\/negative
248
241
-- infinity. These are based on the IEEE representation of non-numbers.
@@ -284,7 +277,7 @@ toCharsNonNumbersAndZero :: forall a mw ew.
284
277
, ew ~ ExponentWord a
285
278
, mw ~ MantissaWord a
286
279
) => SpecialStrings -> a -> Maybe Builder
287
- toCharsNonNumbersAndZero SpecialStrings {.. } f = flip BP. primBounded () . boundString <$>
280
+ toCharsNonNumbersAndZero SpecialStrings {.. } f = string7 <$>
288
281
if w .&. expoMantissaBits == 0
289
282
then Just if w == signBit then negativeZero else positiveZero
290
283
else if w .&. expoMask == expoMask
0 commit comments