[GHC] #9638: Speed up Data.Char.isDigit

GHC ghc-devs at haskell.org
Fri Sep 26 17:33:23 UTC 2014


#9638: Speed up Data.Char.isDigit
-------------------------------------+-------------------------------------
              Reporter:  dfeuer      |            Owner:
                  Type:  feature     |           Status:  new
  request                            |        Milestone:  7.10.1
              Priority:  normal      |          Version:  7.9
             Component:              |         Keywords:
  libraries/base                     |     Architecture:  Unknown/Multiple
            Resolution:              |       Difficulty:  Easy (less than 1
      Operating System:              |  hour)
  Unknown/Multiple                   |       Blocked By:
       Type of failure:  Runtime     |  Related Tickets:
  performance bug                    |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
Changes (by dfeuer):

 * cc: hvr, ekmett (added)
 * component:  Compiler => libraries/base


Comment:

 This approach should also combine well with ways digits are used. For
 instance, we could write (hopefully with better formatting)

 {{{#!hs
 digitToInt :: Char -> Int
 digitToInt c = case ord c - ord '0' of
   d | (fromIntegral d::Word) <= 9 -> d
     | otherwise ->
         case ord c - ord 'a' of
           e | (fromIntegral e::Word) <= 5 -> e + 10
             | otherwise ->
                 case ord c - ord 'A' of
                   f | (fromIntegral f::Word) <= 5 -> f + 10
                     | otherwise = error ("Char.digitToInt: not a digit "
 ++ show c)
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9638#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list