on master help sign in
more efficient content-length parse
fd50079Matt Brown
Network/Wai/Handler/Warp.hs+2−4
@@ -64,6 +64,7 @@ import Control.Exception
64 , fromException
64 , fromException
65 )
65 )
66import Control.Concurrent (forkIO, threadWaitWrite)
66import Control.Concurrent (forkIO, threadWaitWrite)
67+import qualified Data.Char as C
67import Data.Maybe (fromMaybe)
68import Data.Maybe (fromMaybe)
68
69
69import Data.Typeable (Typeable)
70import Data.Typeable (Typeable)
@@ -215,10 +216,7 @@ parseRequest' port (firstLine:otherLines) remoteHost' = do
215 let len =
216 let len =
216 case lookup "content-length" heads of
217 case lookup "content-length" heads of
217 Nothing -> 0
218 Nothing -> 0
218− Just bs ->
219+ Just bs -> fromIntegral $ B.foldl' (\i c -> i * 10 + C.digitToInt c) 0 $ B.takeWhile C.isDigit bs
219− case reads $ B.unpack bs of -- FIXME could probably be optimized
220− (x, _):_ -> x
221− [] -> 0
222 let serverName' = takeUntil 58 host -- ':'
220 let serverName' = takeUntil 58 host -- ':'
223 -- FIXME isolate takes an Integer instead of Int or Int64. If this is a
221 -- FIXME isolate takes an Integer instead of Int or Int64. If this is a
224 -- performance penalty, we may need our own version.
222 -- performance penalty, we may need our own version.