@@ -231,5 +231,31 @@ benchShort = bgroup "ShortByteString"
231231 , bench " FindIndex/inlined" $ nf (S. findIndex (== nl)) absurdlong
232232 , bench " FindIndex/non-inlined" $ nf (S. findIndex (nilEq nl)) absurdlong
233233 ]
234+ , bgroup " ShortByteString unpack/uncons comparison" $
235+ [ bench " unpack and look at first 5 elements" $ nf (unpack5) absurdlong
236+ , bench " uncons consecutively 5 times" $ nf (uncons5) absurdlong
237+ , bench " unconsN 5" $ nf (unconsN) absurdlong
238+ ]
234239 ]
235240
241+
242+ unpack5 :: ShortByteString -> Bool
243+ unpack5 sbs = case S. unpack sbs of
244+ (a: b: c: d: e: _) -> True
245+ _ -> False
246+
247+
248+ uncons5 :: ShortByteString -> Bool
249+ uncons5 sbs
250+ | Just (a, r1) <- S. uncons sbs
251+ , Just (b, r2) <- S. uncons r1
252+ , Just (c, r3) <- S. uncons r2
253+ , Just (d, r4) <- S. uncons r3
254+ , Just (e, xs) <- S. uncons r4 = True
255+ | otherwise = False
256+
257+ unconsN :: ShortByteString -> Bool
258+ unconsN sbs = case S. unconsN 5 sbs of
259+ Just ([a, b, c, d, e], xs) -> True
260+ Just _ -> error " oops"
261+ _ -> False
0 commit comments