Hello community, here is the log from the commit of package ghc-utf8-string for openSUSE:Factory checked in at 2015-08-27 08:56:48 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-utf8-string (Old) and /work/SRC/openSUSE:Factory/.ghc-utf8-string.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-utf8-string" Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-utf8-string/ghc-utf8-string.changes 2015-05-27 12:42:55.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-utf8-string.new/ghc-utf8-string.changes 2015-08-27 08:56:49.000000000 +0200 @@ -1,0 +2,6 @@ +Sun Aug 23 17:53:57 UTC 2015 - mimi...@gmail.com + +- update to 1.0.1 +* Improve the performance of Data.ByteString.Lazy.UTF8.fromString. + +------------------------------------------------------------------- Old: ---- utf8-string-1.tar.gz New: ---- utf8-string-1.0.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-utf8-string.spec ++++++ --- /var/tmp/diff_new_pack.qHheNC/_old 2015-08-27 08:56:49.000000000 +0200 +++ /var/tmp/diff_new_pack.qHheNC/_new 2015-08-27 08:56:49.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package ghc-utf8-string # -# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -19,14 +19,14 @@ %global pkg_name utf8-string Name: ghc-utf8-string -Version: 1 +Version: 1.0.1 Release: 0 Summary: Support for reading and writing UTF8 Strings License: BSD-3-Clause Group: System/Libraries Url: http://hackage.haskell.org/package/%{pkg_name} -Source0: http://hackage.haskell.org/packages/archive/%{pkg_name}/%{version}/%{pkg_name}-%{version}.tar.gz +Source0: http://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: ghc-Cabal-devel ++++++ utf8-string-1.tar.gz -> utf8-string-1.0.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/utf8-string-1/CHANGELOG.markdown new/utf8-string-1.0.1/CHANGELOG.markdown --- old/utf8-string-1/CHANGELOG.markdown 2015-01-23 02:51:29.000000000 +0100 +++ new/utf8-string-1.0.1/CHANGELOG.markdown 2015-08-22 00:38:06.000000000 +0200 @@ -1,3 +1,7 @@ +1.0.1 +----- +* Improve the performance of Data.ByteString.Lazy.UTF8.fromString. (Thanks, ndmitchell) + 1 ----- * Remove out all the old utf8 IO support. GHC supports utf8 now. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/utf8-string-1/Data/ByteString/Lazy/UTF8.hs new/utf8-string-1.0.1/Data/ByteString/Lazy/UTF8.hs --- old/utf8-string-1/Data/ByteString/Lazy/UTF8.hs 2015-01-23 02:51:29.000000000 +0100 +++ new/utf8-string-1.0.1/Data/ByteString/Lazy/UTF8.hs 2015-08-22 00:38:06.000000000 +0200 @@ -38,15 +38,62 @@ import Data.Bits import Data.Word import Data.Int +import Foreign.Storable +import Foreign.Ptr +import Foreign.ForeignPtr +import Data.Char (ord) +import Control.Exception (assert) import qualified Data.ByteString.Lazy as B +import qualified Data.ByteString.Lazy.Internal as B +import qualified Data.ByteString.Internal as S +import System.IO.Unsafe import Prelude hiding (take,drop,splitAt,span,break,foldr,foldl,length,lines) -import Codec.Binary.UTF8.String(encode) import Codec.Binary.UTF8.Generic (buncons) +--------------------------------------------------------------------- +-- ENCODING + -- | Converts a Haskell string into a UTF8 encoded bytestring. fromString :: String -> B.ByteString -fromString xs = B.pack (encode xs) +fromString [] = B.empty +fromString xs0 = packChunks 32 xs0 + where + packChunks n xs = case packUptoLenBytes n xs of + (bs, [] ) -> B.chunk bs B.Empty + (bs, xs') -> B.Chunk bs (packChunks (min (n * 2) B.smallChunkSize) xs') + + packUptoLenBytes :: Int -> String -> (S.ByteString, String) + packUptoLenBytes len xs = unsafeCreateUptoN' len $ \ptr -> do + (end, xs') <- go ptr (ptr `plusPtr` (len-4)) xs + return (end `minusPtr` ptr, xs') + + -- end is the last position at which you can write a whole 4 byte sequence safely + go :: Ptr Word8 -> Ptr Word8 -> String -> IO (Ptr Word8, String) + go !ptr !end xs | ptr > end = return (ptr, xs) + go !ptr !_ [] = return (ptr, []) + go !ptr !end (x:xs) + | x <= '\x7f' = poke ptr (S.c2w x) >> go (plusPtr ptr 1) end xs + | otherwise = case ord x of + oc | oc <= 0x7ff -> do + poke ptr $ fromIntegral $ 0xc0 + (oc `shiftR` 6) + pokeElemOff ptr 1 $ fromIntegral $ 0x80 + oc .&. 0x3f + go (plusPtr ptr 2) end xs + | oc <= 0xffff -> do + poke ptr $ fromIntegral $ 0xe0 + (oc `shiftR` 12) + pokeElemOff ptr 1 $ fromIntegral $ 0x80 + ((oc `shiftR` 6) .&. 0x3f) + pokeElemOff ptr 2 $ fromIntegral $ 0x80 + oc .&. 0x3f + go (plusPtr ptr 3) end xs + | otherwise -> do + poke ptr $ fromIntegral $ 0xf0 + (oc `shiftR` 18) + pokeElemOff ptr 1 $ fromIntegral $ 0x80 + ((oc `shiftR` 12) .&. 0x3f) + pokeElemOff ptr 2 $ fromIntegral $ 0x80 + ((oc `shiftR` 6) .&. 0x3f) + pokeElemOff ptr 3 $ fromIntegral $ 0x80 + oc .&. 0x3f + go (plusPtr ptr 4) end xs + + +--------------------------------------------------------------------- +-- DECODING -- | Convert a UTF8 encoded bytestring into a Haskell string. -- Invalid characters are replaced with '\xFFFD'. @@ -221,3 +268,20 @@ in xs : lines' ys Nothing -> [bs] + +--------------------------------------------------------------------- +-- COPIED FROM BYTESTRING +-- These functions are copied verbatum from Data.ByteString.Internal +-- I suspect their lack of export is an oversight + +unsafeCreateUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> (S.ByteString, a) +unsafeCreateUptoN' l f = unsafeDupablePerformIO (createUptoN' l f) +{-# INLINE unsafeCreateUptoN' #-} + +-- | Create ByteString of up to size @l@ and use action @f@ to fill it's contents which returns its true size. +createUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> IO (S.ByteString, a) +createUptoN' l f = do + fp <- S.mallocByteString l + (l', res) <- withForeignPtr fp $ \p -> f p + assert (l' <= l) $ return (S.PS fp 0 l', res) +{-# INLINE createUptoN' #-} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/utf8-string-1/utf8-string.cabal new/utf8-string-1.0.1/utf8-string.cabal --- old/utf8-string-1/utf8-string.cabal 2015-01-23 02:51:29.000000000 +0100 +++ new/utf8-string-1.0.1/utf8-string.cabal 2015-08-22 00:38:06.000000000 +0200 @@ -1,5 +1,5 @@ Name: utf8-string -Version: 1 +Version: 1.0.1 Author: Eric Mertens Maintainer: emert...@galois.com License: BSD3