File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 1
- {-# LANGUAGE CPP #-}
1
+ {-# LANGUAGE BangPatterns #-}
2
+ {-# LANGUAGE CPP #-}
2
3
module Data.Aeson.Internal.Text (
3
4
unsafeDecodeASCII ,
4
5
) where
5
6
6
- import Data.ByteString (ByteString )
7
- import Data.Text (Text )
7
+ import Data.ByteString (ByteString )
8
+ import Data.Text (Text , empty )
8
9
9
- import qualified Data.Text.Encoding as TE
10
+
11
+ #if MIN_VERSION_text(2,0,0)
12
+ import Data.Text.Array (Array (.. ))
13
+ import Data.Text.Internal (Text (.. ))
14
+
15
+ import qualified Data.ByteString.Short.Internal as SBS
16
+
17
+ import Data.Aeson.Internal.ByteString
18
+
19
+ #else
20
+ import qualified Data.Text.Encoding as TE
21
+
22
+ #endif
10
23
11
24
-- | The input is assumed to contain only 7bit ASCII characters (i.e. @< 0x80@).
12
25
-- We use TE.decodeLatin1 here because TE.decodeASCII is currently (text-1.2.4.0)
13
26
-- deprecated and equal to TE.decodeUtf8, which is slower than TE.decodeLatin1.
14
27
unsafeDecodeASCII :: ByteString -> Text
15
28
16
29
#if MIN_VERSION_text(2,0,0)
17
- unsafeDecodeASCII = TE. decodeASCII
30
+ unsafeDecodeASCII bs = withBS bs $ \ _fp len -> if len == 0 then empty else
31
+ let ! (SBS. SBS arr) = SBS. toShort bs in Text (ByteArray arr) 0 len
32
+
18
33
#else
19
34
unsafeDecodeASCII = TE. decodeLatin1
20
35
#endif
You can’t perform that action at this time.
0 commit comments