on master help sign in
A local definition of digitToInt speeds decimal parsing up about 15%.
commit5b02ca7e0cb425f9f4f4051f308dfd4a52621259 authorBryan O'Sullivan <bos@serpentine.com> dateThu 21 Oct 2010, 21:42 (16 years ago) parentad6e285
1 file changed+13−4
Data/Text/Read.hs+13−4
Data/Text/Read.hs+13−4
@@ -22,8 +22,8 @@ module Data.Text.Read
2222 ) where
2323
2424import Control.Monad (liftM)
25−import Data.Char (digitToInt, isDigit, isHexDigit, ord)
26−import Data.Ratio
25+import Data.Char (isDigit, isHexDigit, ord)
26+import Data.Ratio ((%))
2727import Data.Text as T
2828
2929-- | Read some text, and if the read succeeds, return its value and
@@ -56,8 +56,17 @@ hexadecimal txt
5656 | otherwise = hex txt
5757 where (h,t) = T.splitAt 2 txt
5858
59−-- | Read a leading sign character (@\'-\'@ or @\'+\'@) and apply it
60−-- to the result of applying the given reader.
59+hexDigitToInt :: Char -> Int
60+hexDigitToInt c
61+ | c >= '0' && c <= '9' = ord c - ord '0'
62+ | c >= 'a' && c <= 'f' = ord c - (ord 'a' - 10)
63+ | otherwise = ord c - (ord 'A' - 10)
64+
65+digitToInt :: Char -> Int
66+digitToInt c = ord c - ord '0'
67+
68+-- | Read an optional leading sign character (@\'-\'@ or @\'+\'@) and
69+-- apply it to the result of applying the given reader.
6170signed :: Num a => Reader a -> Reader a
6271{-# INLINE signed #-}
6372signed f = runP (signa (P f))