on master help sign in
Unroll static mconcats
commit66180a8a7cbfec4d75182e42250ff87bab8f9060 authorMichael Snoyman <michael@snoyman.com> dateThu 13 Jan 2011, 21:03 (16 years ago) parent9b8c215
1 file changed+20−23
Network/Wai/Handler/Warp.hs+20−23
Network/Wai/Handler/Warp.hs+20−23
@@ -195,26 +195,25 @@ parseFirst s = do
195195 return (method, rpath, qstring, hsecond)
196196
197197headers :: HttpVersion -> Status -> ResponseHeaders -> Bool -> Builder
198−headers httpversion status responseHeaders isChunked' = mconcat
199− [ copyByteString "HTTP/"
200− , copyByteString httpversion
201− , fromChar ' '
202− , fromString $ show $ statusCode status
203− , fromChar ' '
204− , copyByteString $ statusMessage status
205− , copyByteString "\r\n"
206− , mconcat $ map go responseHeaders
207− , if isChunked'
208− then copyByteString "Transfer-Encoding: chunked\r\n\r\n"
209− else copyByteString "\r\n"
210− ]
198+headers httpversion status responseHeaders isChunked' =
199+ copyByteString "HTTP/"
200+ `mappend` copyByteString httpversion
201+ `mappend` fromChar ' '
202+ `mappend` fromString $ show $ statusCode status
203+ `mappend` fromChar ' '
204+ `mappend` copyByteString $ statusMessage status
205+ `mappend` copyByteString "\r\n"
206+ `mappend` mconcat (map go responseHeaders)
207+ `mappend`
208+ if isChunked'
209+ then copyByteString "Transfer-Encoding: chunked\r\n\r\n"
210+ else copyByteString "\r\n"
211211 where
212− go (x, y) = mconcat
213− [ copyByteString $ ciOriginal x
214− , copyByteString ": "
215− , copyByteString y
216− , copyByteString "\r\n"
217− ]
212+ go (x, y) =
213+ copyByteString $ ciOriginal x
214+ `mappend` copyByteString ": "
215+ `mappend` copyByteString y
216+ `mappend` copyByteString "\r\n"
218217
219218isChunked :: HttpVersion -> Bool
220219isChunked = (==) http11
@@ -273,10 +272,8 @@ sendResponse req hv socket (ResponseEnumerator res) =
273272 chunk = E.checkDone $ E.continue . step
274273 step k E.EOF = k (E.Chunks [chunkedTransferTerminator]) >>== return
275274 step k (E.Chunks []) = E.continue $ step k
276− step k (E.Chunks builders) =
277− k (E.Chunks [chunked]) >>== chunk
278− where
279− chunked = chunkedTransferEncoding $ mconcat builders
275+ -- FIXME ensure that the mconcat on the concents here is unnecessary
276+ step k x = k x >>== chunk
280277
281278parseHeaderNoAttr :: ByteString -> (ByteString, ByteString)
282279parseHeaderNoAttr s =