Skip to content

Commit

Permalink
Additional quick filter in isSpaceWord8
Browse files Browse the repository at this point in the history
  • Loading branch information
ethercrow committed Oct 26, 2020
1 parent c4e44bd commit 9127d6e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Data/ByteString/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import Data.String (IsString(..))

import Control.Exception (assert)

import Data.Bits ((.&.))
import Data.Char (ord)
import Data.Word (Word8)

Expand Down Expand Up @@ -677,10 +678,11 @@ isSpaceWord8 w8 =
-- the conversion from Word8 to Word is free.
let w :: Word
!w = fromIntegral w8
in w - 0x21 > 0x7e -- not [x21..0x9f]
&& ( w == 0x20 -- SP
|| w - 0x09 < 5 -- HT, NL, VT, FF, CR
|| w == 0xa0 ) -- NBSP
in w .&. 0x50 == 0 -- Quick non-whitespace filter
&& w - 0x21 > 0x7e -- Second non-whitespace filter
&& ( w == 0x20 -- SP
|| w == 0xa0 -- NBSP
|| w - 0x09 < 5) -- HT, NL, VT, FF, CR
{-# INLINE isSpaceWord8 #-}

-- | Selects white-space characters in the Latin-1 range
Expand Down

0 comments on commit 9127d6e

Please sign in to comment.