on master help sign in
Optimize parseHeaderNoAttr (code from Matt)
commit2277409524c2005da5f6593f913fa06cbc098327 authorMichael Snoyman <michael@snoyman.com> dateFri 14 Jan 2011, 11:42 (16 years ago) parent4816758
1 file changed+8−11
Network/Wai/Handler/Warp.hs+8−11
Network/Wai/Handler/Warp.hs+8−11
@@ -44,8 +44,6 @@ import Data.Maybe (fromMaybe)
4444
4545import Data.Typeable (Typeable)
4646
47−import Control.Arrow (first)
48−
4947import Data.Enumerator (($$), (>>==))
5048import qualified Data.Enumerator as E
5149import Blaze.ByteString.Builder.Enumerator (builderToByteString)
@@ -161,7 +159,7 @@ parseRequest' port (firstLine:otherLines) remoteHost' = do
161159 else if '/' == B.head rpath'
162160 then "/"
163161 else B.cons '/' rpath'
164− let heads = map (first mkCIByteString . parseHeaderNoAttr) otherLines
162+ let heads = map parseHeaderNoAttr otherLines
165163 let host = fromMaybe "" $ lookup "host" heads
166164 let len =
167165 case lookup "content-length" heads of
@@ -288,16 +286,15 @@ sendResponse req hv socket (ResponseEnumerator res) =
288286 -- FIXME ensure that the mconcat on the concents here is unnecessary
289287 step k x = k x >>== chunk
290288
291−parseHeaderNoAttr :: ByteString -> (ByteString, ByteString)
289+parseHeaderNoAttr :: ByteString -> (CIByteString, ByteString)
292290parseHeaderNoAttr s =
293− let (k, rest) = B.span (/= ':') s
294− rest' = if not (B.null rest) &&
295− B.head rest == ':' &&
296− not (B.null $ B.tail rest) &&
297− B.head (B.tail rest) == ' '
298− then B.drop 2 rest
291+ let (k, rest) = S.breakByte 58 s -- ':'
292+ restLen = S.length rest
293+ -- FIXME check for colon without following space?
294+ rest' = if restLen > 1 && SU.unsafeTake 2 rest == ": "
295+ then SU.unsafeDrop 2 rest
299296 else rest
300− in (k, rest')
297+ in (mkCIByteString k, rest')
301298
302299requestBodyHandle :: Int
303300 -> E.Enumeratee ByteString ByteString IO a