bytestring-lexing 0.3.0 → 0.4.0
raw patch · 5 files changed
+187/−6 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.ByteString.Lex.Integral: readDecimal_ :: Integral a => ByteString -> a
Files
- AUTHORS +13/−0
- README +37/−0
- VERSION +16/−0
- bytestring-lexing.cabal +9/−5
- src/Data/ByteString/Lex/Integral.hs +112/−1
+ AUTHORS view
@@ -0,0 +1,13 @@+Haskell bytestring-lexing package AUTHORS/THANKS file:++The bytestring-lexing package was originally written by Don Stewart+and released under the terms in the LICENSE file. In January 2012+maintainership was taken over by wren ng thornton. I would also+like to give thanks to the following contributers:++Bryan O'Sullivan --- For adding support for parsing Doubles from+ lazy bytestrings back during Don's maintainership.++Erik de Castro Lopo, Vincent Hanquez, and Christoph Breitkopf ---+ for excessive tweaking and benchmarking of the readDecimal+ function.
+ README view
@@ -0,0 +1,37 @@+bytestring-lexing+=================++This is a relatively simple package and should be easy to install.+It requires Alex for generating the Double lexers. Once that is+installed, you should be able to use one of the following standard+methods to install it.++ -- With cabal-install and without the source:+ $> cabal install bytestring-lexing+ + -- With cabal-install and with the source already:+ $> cd bytestring-lexing+ $> cabal install+ + -- Without cabal-install, but with the source already:+ $> cd bytestring-lexing+ $> runhaskell Setup.hs configure --user+ $> runhaskell Setup.hs build+ $> runhaskell Setup.hs test+ $> runhaskell Setup.hs haddock --hyperlink-source+ $> runhaskell Setup.hs install++The test step is optional and currently does nothing.+++Portability+===========++An attempt has been made to keep this library portable. However,+it relies on some language extensions which have been accepted into+the Haskell standard following the Haskell98 report. All the required+language extensions are:++FFI++----------------------------------------------------------- fin.
+ VERSION view
@@ -0,0 +1,16 @@+0.4.0 (2012.00.00):+ - Data.ByteString.Lex.Integral: added readDecimal_++0.3.0 (2012.01.28):+ - Added Data.ByteString.Lex.Integral+ - Converted repo to Darcs-2 hashed format.+ - wren ng thornton took over maintainership.++0.2.1 (2010.02.14):+0.2 (2008.10.15):+ - Add support for lexing lazy bytestrings.++0.1.2 (2008.07.23):+0.1.0.2 (2008.07.23):+0.1.0.1 (2008.07.19):+0.1.0 (2008.07.19):
bytestring-lexing.cabal view
@@ -1,9 +1,9 @@ ------------------------------------------------------------------- wren ng thornton <wren@community.haskell.org> ~ 2012.01.25+-- wren ng thornton <wren@community.haskell.org> ~ 2012.02.03 ---------------------------------------------------------------- Name: bytestring-lexing-Version: 0.3.0+Version: 0.4.0 -- Source-Repository requires version 1.6 Cabal-Version: >= 1.6 Build-Type: Simple@@ -15,10 +15,14 @@ Maintainer: wren@community.haskell.org Homepage: http://code.haskell.org/~wren/ Category: Data-Synopsis: Parse literals efficiently from strict or lazy bytestrings-Description: Parse literals efficiently from strict or lazy bytestrings+Synopsis: Parse and produce literals efficiently from strict or lazy bytestrings.+Description:+ Parse and produce literals efficiently from strict or lazy bytestrings.+ .+ Some benchmarks for this package can be found at: <http://community.haskell.org/~wren/bytestring-lexing/test/bench/html> -Tested-With: GHC ==6.8.2, GHC ==6.10.1, GHC ==6.12.1, GHC ==7.0.3+Extra-source-files: AUTHORS, README, VERSION+Tested-With: GHC ==6.8.2, GHC ==6.10.1, GHC ==6.12.1, GHC ==7.0.3 Source-Repository head Type: darcs Location: http://community.haskell.org/~wren/bytestring-lexing
src/Data/ByteString/Lex/Integral.hs view
@@ -1,6 +1,6 @@ {-# OPTIONS_GHC -Wall -fwarn-tabs #-} ------------------------------------------------------------------- 2012.01.27+-- 2012.01.31 -- | -- Module : Data.ByteString.Lex.Integral -- Copyright : Copyright (c) 2010--2012 wren ng thornton@@ -20,6 +20,7 @@ -- , packSigned -- * Decimal conversions , readDecimal+ , readDecimal_ , packDecimal -- TODO: asDecimal -- this will be really hard to make efficient... -- * Hexadecimal conversions@@ -216,6 +217,116 @@ (m*1000000000 + fromIntegral (addDigit n w)) (BSU.unsafeTail xs) | otherwise -> (m*100000000 + fromIntegral n, xs)++----------------------------------------------------------------++-- | A variant of 'readDecimal' which does not return the tail of+-- the string, and returns @0@ instead of @Nothing@. This is twice+-- as fast for 'Int64' on 32-bit systems, but has identical performance+-- to 'readDecimal' for all other types and architectures.+readDecimal_ :: Integral a => ByteString -> a+{-# SPECIALIZE readDecimal_ ::+ ByteString -> Int,+ ByteString -> Int8,+ ByteString -> Int16,+ ByteString -> Int32,+ ByteString -> Int64,+ ByteString -> Integer,+ ByteString -> Word,+ ByteString -> Word8,+ ByteString -> Word16,+ ByteString -> Word32,+ ByteString -> Word64 #-}+readDecimal_ = start+ where+ isDecimal :: Word8 -> Bool+ {-# INLINE isDecimal #-}+ isDecimal w = 0x39 >= w && w >= 0x30+ + toDigit :: Integral a => Word8 -> a+ {-# INLINE toDigit #-}+ toDigit w = fromIntegral (w - 0x30)+ + addDigit :: Int -> Word8 -> Int+ {-# INLINE addDigit #-}+ addDigit n w = n * 10 + toDigit w+ + start xs+ | BS.null xs = 0+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop0 (toDigit w) (BSU.unsafeTail xs)+ | otherwise -> 0+ + loop0 :: Integral a => a -> ByteString -> a+ loop0 m xs+ | m `seq` xs `seq` False = undefined+ | BS.null xs = m+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop1 m (toDigit w) (BSU.unsafeTail xs)+ | otherwise -> m+ + loop1, loop2, loop3, loop4, loop5, loop6, loop7, loop8+ :: Integral a => a -> Int -> ByteString -> a+ loop1 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*10 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop2 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*10 + fromIntegral n+ loop2 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*100 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop3 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*100 + fromIntegral n+ loop3 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*1000 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop4 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*1000 + fromIntegral n+ loop4 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*10000 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop5 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*10000 + fromIntegral n+ loop5 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*100000 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop6 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*100000 + fromIntegral n+ loop6 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*1000000 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop7 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*1000000 + fromIntegral n+ loop7 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*10000000 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop8 m (addDigit n w) (BSU.unsafeTail xs)+ | otherwise -> m*10000000 + fromIntegral n+ loop8 m n xs+ | m `seq` n `seq` xs `seq` False = undefined+ | BS.null xs = m*100000000 + fromIntegral n+ | otherwise =+ case BSU.unsafeHead xs of+ w | isDecimal w -> loop0+ (m*1000000000 + fromIntegral (addDigit n w))+ (BSU.unsafeTail xs)+ | otherwise -> m*100000000 + fromIntegral n ---------------------------------------------------------------- -- | Convert a non-negative integer into an (unsigned) ASCII decimal