on master help sign in
Optimize parseHeaderNoAttr (code from Matt)
2277409Michael Snoyman
Network/Wai/Handler/Warp.hs+8−11
@@ -44,8 +44,6 @@ import Data.Maybe (fromMaybe)
44
44
45import Data.Typeable (Typeable)
45import Data.Typeable (Typeable)
46
46
47−import Control.Arrow (first)
48−
49import Data.Enumerator (($$), (>>==))
47import Data.Enumerator (($$), (>>==))
50import qualified Data.Enumerator as E
48import qualified Data.Enumerator as E
51import Blaze.ByteString.Builder.Enumerator (builderToByteString)
49import Blaze.ByteString.Builder.Enumerator (builderToByteString)
@@ -161,7 +159,7 @@ parseRequest' port (firstLine:otherLines) remoteHost' = do
161 else if '/' == B.head rpath'
159 else if '/' == B.head rpath'
162 then "/"
160 then "/"
163 else B.cons '/' rpath'
161 else B.cons '/' rpath'
164− let heads = map (first mkCIByteString . parseHeaderNoAttr) otherLines
162+ let heads = map parseHeaderNoAttr otherLines
165 let host = fromMaybe "" $ lookup "host" heads
163 let host = fromMaybe "" $ lookup "host" heads
166 let len =
164 let len =
167 case lookup "content-length" heads of
165 case lookup "content-length" heads of
@@ -288,16 +286,15 @@ sendResponse req hv socket (ResponseEnumerator res) =
288 -- FIXME ensure that the mconcat on the concents here is unnecessary
286 -- FIXME ensure that the mconcat on the concents here is unnecessary
289 step k x = k x >>== chunk
287 step k x = k x >>== chunk
290
288
291−parseHeaderNoAttr :: ByteString -> (ByteString, ByteString)
289+parseHeaderNoAttr :: ByteString -> (CIByteString, ByteString)
292parseHeaderNoAttr s =
290parseHeaderNoAttr s =
293− let (k, rest) = B.span (/= ':') s
291+ let (k, rest) = S.breakByte 58 s -- ':'
294− rest' = if not (B.null rest) &&
292+ restLen = S.length rest
295− B.head rest == ':' &&
293+ -- FIXME check for colon without following space?
296− not (B.null $ B.tail rest) &&
294+ rest' = if restLen > 1 && SU.unsafeTake 2 rest == ": "
297− B.head (B.tail rest) == ' '
298− then B.drop 2 rest
295+ then SU.unsafeDrop 2 rest
299 else rest
296 else rest
300− in (k, rest')
297+ in (mkCIByteString k, rest')
301
298
302requestBodyHandle :: Int
299requestBodyHandle :: Int
303 -> E.Enumeratee ByteString ByteString IO a
300 -> E.Enumeratee ByteString ByteString IO a