isSpace is too slow

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun May 27 06:32:09 EDT 2007


Hello Ketil,

Monday, May 21, 2007, 12:43:16 PM, you wrote:

isSpace :: Char ->> Bool
> isSpace = isSp . ord
> isSp c | c <= 13    = c >= 8  -- \b..\r
>        | c <= 127   = c == 32 -- ' '
>        | c <= 255   = c == 0xa0 -- nbsp
>        | otherwise      = iswspace(..)

that's great but array-based test should be even faster:

> isSp c | c <= 255   = spaceArray!c /= 0
>        | otherwise  = iswspace(..)

spaceArray :: UArray Int Word8

moreover, we can do the same trick as done in C libraries - pack
several boolean tests into one Word8. but probably, direct use of
isspace will be even better:

> isSp c | c <= 255   = isspace c
>        | otherwise  = iswspace(..)

> foreign unsafe import isspace ...
> foreign unsafe import iswspace ...


moreover, if we know platforms where iswpace checks the whole range,
we can speed up code on these platforms by omitting isspace check


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Glasgow-haskell-users mailing list