on master help sign in
Tidy up the code a little.
commit22ce505f30c3e4b65bdf5f946e793401d4a968f0 authorBryan O'Sullivan <bos@mailrank.com> dateTue 22 Mar 2011, 15:32 (16 years ago) parentb94053c
1 file changed+8−34
Data/Aeson/Encode.hs+8−34
Data/Aeson/Encode.hs+8−34
@@ -74,24 +74,20 @@ writeJSONChar c =
7474 '\n' -> writeByteString "\\n"
7575 '\r' -> writeByteString "\\r"
7676 '\t' -> writeByteString "\\t"
77− _ | c < '\x20' -> writeChar '\\' `mappend`
78− writeChar 'u' `mappend`
79− -- FIXME: Why do we have to use Word16 where Word8 would suffice?
80− writeWord16Hex (fromIntegral $ fromEnum c)
77+ _ | c < '\x20' -> writeByteString "\\u00" `mappend`
78+ writeWord8Hex (fromIntegral $ fromEnum c)
8179 | otherwise -> writeChar c
8280
8381-- TODO: Extend blaze-builder or better the new bytestring lib with support for
8482-- hex encoding.
8583
86−{-# INLINE writeWord16Hex #-}
87−writeWord16Hex :: Word16 -> Write
88−writeWord16Hex = exactWrite 4 . pokeWord16Hex
84+{-# INLINE writeWord8Hex #-}
85+writeWord8Hex :: Word8 -> Write
86+writeWord8Hex = exactWrite 2 . pokeWord8Hex
8987
90−{-# INLINE pokeWord16Hex #-}
91−pokeWord16Hex :: Word16 -> Ptr Word8 -> IO ()
92−pokeWord16Hex x op = do
93− pokeNibble 0 12
94− pokeNibble 1 8
88+{-# INLINE pokeWord8Hex #-}
89+pokeWord8Hex :: Word8 -> Ptr Word8 -> IO ()
90+pokeWord8Hex x op = do
9591 pokeNibble 2 4
9692 pokeNibble 3 0
9793 where
@@ -133,27 +129,5 @@ fromWriteStream write =
133129fromWriteText :: (Char -> Write) -> T.Text -> Builder
134130fromWriteText w = fromWriteStream w . F.stream
135131
136−{-
137−fromWriteList :: (a -> Write) -> [a] -> Builder
138−fromWriteList write =
139− makeBuilder
140− where
141− makeBuilder xs0 = fromBuildStepCont $ step xs0
142− where
143− step xs1 k !(BufRange op0 ope0) = go xs1 op0
144− where
145− go [] !op = do
146− let !br' = BufRange op ope0
147− k br'
148−
149− go xs@(x':xs') !op
150− | op `plusPtr` maxSize <= ope0 = do
151− !op' <- runPoke wio op
152− go xs' op'
153− | otherwise = return $ bufferFull maxSize op (step xs k)
154− where
155− Write maxSize wio = write x'
156−{-# INLINE fromWriteList #-}
157−-}
158132
159133