File tree Expand file tree Collapse file tree 2 files changed +18
-30
lines changed Expand file tree Collapse file tree 2 files changed +18
-30
lines changed Original file line number Diff line number Diff line change @@ -11,15 +11,21 @@ import qualified "aeson-benchmarks" Data.Aeson.Parser.UnescapeFFI as FFI
11
11
import qualified "aeson-benchmarks" Data.Aeson.Parser.UnescapePure as Pure
12
12
13
13
import qualified Data.ByteString.Char8 as BS
14
-
15
- n :: Int
16
- n = 10000
17
-
18
- input :: BS. ByteString
19
- input = BS. concat $ replicate n $ BS. pack " \\\" "
14
+ import System.Environment (getArgs , withArgs )
20
15
21
16
main :: IO ()
22
- main = defaultMain
17
+ main = do
18
+ args_ <- getArgs
19
+ let (args, p, n) =
20
+ case args_ of
21
+ " --pattern" : p : args_ -> k p args_
22
+ _ -> k " \\\" " args_
23
+ k p args_ =
24
+ case args_ of
25
+ " --repeat" : n : args_ -> (args_, p, read n)
26
+ args_ -> (args_, p, 10000 )
27
+ input = BS. concat $ replicate n $ BS. pack p
28
+ withArgs args $ defaultMain
23
29
[ bench " ffi" $ whnf FFI. unescapeText input
24
30
, bench " pure" $ whnf Pure. unescapeText input
25
31
]
Original file line number Diff line number Diff line change @@ -120,29 +120,11 @@ decode UtfTail1 point word = case word of
120
120
_ -> throwDecodeError
121
121
122
122
decodeHex :: Word8 -> Word16
123
- decodeHex 48 = 0 -- '0'
124
- decodeHex 49 = 1 -- '1'
125
- decodeHex 50 = 2 -- '2'
126
- decodeHex 51 = 3 -- '3'
127
- decodeHex 52 = 4 -- '4'
128
- decodeHex 53 = 5 -- '5'
129
- decodeHex 54 = 6 -- '6'
130
- decodeHex 55 = 7 -- '7'
131
- decodeHex 56 = 8 -- '8'
132
- decodeHex 57 = 9 -- '9'
133
- decodeHex 65 = 10 -- 'A'
134
- decodeHex 97 = 10 -- 'a'
135
- decodeHex 66 = 11 -- 'B'
136
- decodeHex 98 = 11 -- 'b'
137
- decodeHex 67 = 12 -- 'C'
138
- decodeHex 99 = 12 -- 'c'
139
- decodeHex 68 = 13 -- 'D'
140
- decodeHex 100 = 13 -- 'd'
141
- decodeHex 69 = 14 -- 'E'
142
- decodeHex 101 = 14 -- 'e'
143
- decodeHex 70 = 15 -- 'F'
144
- decodeHex 102 = 15 -- 'f'
145
- decodeHex _ = throwDecodeError
123
+ decodeHex x
124
+ | 48 <= x && x <= 57 = fromIntegral x - 48 -- 0-9
125
+ | 65 <= x && x <= 70 = fromIntegral x - 55 -- A-F
126
+ | 97 <= x && x <= 102 = fromIntegral x - 87 -- a-f
127
+ | otherwise = throwDecodeError
146
128
147
129
unescapeText' :: ByteString -> Text
148
130
unescapeText' bs = runText $ \ done -> do
You can’t perform that action at this time.
0 commit comments