Repository : ssh://darcs.haskell.org//srv/darcs/packages/bytestring

On branch  : ghc-7.6

http://hackage.haskell.org/trac/ghc/changeset/84f7f83933abb932237a1ae0a01f96c4e1408a52

>---------------------------------------------------------------

commit 84f7f83933abb932237a1ae0a01f96c4e1408a52
Author: Duncan Coutts <[email protected]>
Date:   Wed Sep 5 01:22:34 2012 +0000

    Simplify the implementation of unsnoc
    We have to do two traversals either way, no saving.

>---------------------------------------------------------------

 Data/ByteString/Lazy.hs |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/Data/ByteString/Lazy.hs b/Data/ByteString/Lazy.hs
index 709b173..7755cb3 100644
--- a/Data/ByteString/Lazy.hs
+++ b/Data/ByteString/Lazy.hs
@@ -409,13 +409,11 @@ init (Chunk c0 cs0) = go c0 cs0
 
 -- | /O(n\/c)/ Extract the 'init' and 'last' of a ByteString, returning Nothing
 -- if it is empty.
+--
+-- * It is no faster than using 'init' and 'last'
 unsnoc :: ByteString -> Maybe (ByteString, Word8)
-unsnoc Empty = Nothing
-unsnoc (Chunk c0 cs0) = Just (go id c0 cs0)
-  where go r c Empty = (r $ if S.null i then Empty else Chunk i Empty, l)
-          where i = S.unsafeInit c
-                l = S.unsafeLast c
-        go r c (Chunk c' cs) = go (r . Chunk c) c' cs
+unsnoc Empty        = Nothing
+unsnoc (Chunk c cs) = Just (init (Chunk c cs), last (Chunk c cs))
 
 -- | /O(n\/c)/ Append two ByteStrings
 append :: ByteString -> ByteString -> ByteString



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to