on master help sign in
Fast path the ascii utf8 decoding case
d6f08aaHarendra Kumar
src/Streamly/Streams/StreamD.hs+41−28
@@ -3075,20 +3075,27 @@ decodeUtf8With cfm (Stream step state) = Stream step' (FreshPoint 0 0 state)
3075 return $
3075 return $
3076 case r of
3076 case r of
3077 Yield x s ->
3077 Yield x s ->
3078+ if statePtr == 0 && x <= 0x7f
3079+ then
3080+ Skip $
3081+ YieldAndContinue
3082+ (unsafeChr (fromIntegral x))
3083+ (FreshPoint 0 0 s)
3084+ else
3078− let (Tuple' sv cp) =
3085+ let (Tuple' sv cp) =
3079− decode statePtr codepointPtr x
3086+ decode statePtr codepointPtr x
3080− in case sv of
3087+ in case sv of
3081− 12 ->
3088+ 12 ->
3082− Skip $
3089+ Skip $
3083− transliterateOrError
3090+ transliterateOrError
3084− "Streamly.Streams.StreamD.decodeUtf8With: Invalid UTF8 codepoint encountered"
3091+ "Streamly.Streams.StreamD.decodeUtf8With: Invalid UTF8 codepoint encountered"
3085− (FreshPoint 0 0 s)
3092+ (FreshPoint 0 0 s)
3086− 0 ->
3093+ 0 ->
3087− Skip $
3094+ Skip $
3088− YieldAndContinue
3095+ YieldAndContinue
3089− (unsafeChr (fromIntegral cp))
3096+ (unsafeChr (fromIntegral cp))
3090− (FreshPoint cp sv s)
3097+ (FreshPoint cp sv s)
3091− _ -> Skip (FreshPoint cp sv s)
3098+ _ -> Skip (FreshPoint cp sv s)
3092 Skip s -> Skip (FreshPoint codepointPtr statePtr s)
3099 Skip s -> Skip (FreshPoint codepointPtr statePtr s)
3093 Stop ->
3100 Stop ->
3094 if statePtr /= 0
3101 if statePtr /= 0
@@ -3162,20 +3169,26 @@ decodeUtf8ArraysWith cfm (Stream step state) =
3162 r <- peek p
3169 r <- peek p
3163 touchForeignPtr startf
3170 touchForeignPtr startf
3164 return r
3171 return r
3172+ if statePtr == 0 && x <= 0x7f
3173+ then
3174+ return $ Skip $ YAndC
3175+ (unsafeChr (fromIntegral x))
3176+ (InnerLoop 0 0 st startf (p `plusPtr` 1) end)
3177+ else do
3165− let (Tuple' sv cp) = decode statePtr codepointPtr x
3178+ let (Tuple' sv cp) = decode statePtr codepointPtr x
3166− return $
3179+ return $
3167− case sv of
3180+ case sv of
3168− 12 ->
3181+ 12 ->
3169− Skip $
3182+ Skip $
3170− transliterateOrError
3183+ transliterateOrError
3171− "Streamly.Streams.StreamD.decodeUtf8ArraysWith: Invalid UTF8 codepoint encountered"
3184+ "Streamly.Streams.StreamD.decodeUtf8ArraysWith: Invalid UTF8 codepoint encountered"
3172− (InnerLoop 0 0 st startf (p `plusPtr` 1) end)
3185+ (InnerLoop 0 0 st startf (p `plusPtr` 1) end)
3173− 0 ->
3186+ 0 ->
3174− Skip $
3187+ Skip $
3175− YAndC
3188+ YAndC
3176− (unsafeChr (fromIntegral cp))
3189+ (unsafeChr (fromIntegral cp))
3177− (InnerLoop cp sv st startf (p `plusPtr` 1) end)
3190+ (InnerLoop cp sv st startf (p `plusPtr` 1) end)
3178− _ -> Skip (InnerLoop cp sv st startf (p `plusPtr` 1) end)
3191+ _ -> Skip (InnerLoop cp sv st startf (p `plusPtr` 1) end)
3179 step' _ (YAndC c s) = return $ Yield c s
3192 step' _ (YAndC c s) = return $ Yield c s
3180 step' _ D = return Stop
3193 step' _ D = return Stop
3181
3194