on master help sign in
Optimise `toText` (~10x speedup) & `fromText` (~2x speedup)
023f84cHerbert Valerio Riedel
uuid-types/Data/UUID/Types/Internal.hs+3−3
@@ -68,7 +68,7 @@ import qualified Data.ByteString.Internal as BI
68import qualified Data.ByteString.Lazy as BL
68import qualified Data.ByteString.Lazy as BL
69import qualified Data.ByteString.Unsafe as BU
69import qualified Data.ByteString.Unsafe as BU
70import Data.Text (Text)
70import Data.Text (Text)
71−import qualified Data.Text as T
71+import qualified Data.Text.Encoding as T
72
72
73import Data.UUID.Types.Internal.Builder
73import Data.UUID.Types.Internal.Builder
74
74
@@ -351,11 +351,11 @@ toString uuid = hexw w0 $ hexw' w1 $ hexw' w2 $ hexw w3 ""
351-- | If the passed in `Text` can be parsed as an ASCII representation of
351-- | If the passed in `Text` can be parsed as an ASCII representation of
352-- a `UUID`, it will be. The hyphens may not be omitted.
352-- a `UUID`, it will be. The hyphens may not be omitted.
353fromText :: Text -> Maybe UUID
353fromText :: Text -> Maybe UUID
354−fromText = fromString . T.unpack
354+fromText = fromASCIIBytes . T.encodeUtf8
355
355
356-- | Convert a UUID into a hyphentated string using lower-case letters.
356-- | Convert a UUID into a hyphentated string using lower-case letters.
357toText :: UUID -> Text
357toText :: UUID -> Text
358−toText = T.pack . toString
358+toText = T.decodeLatin1 . toASCIIBytes
359
359
360-- | Convert a UUID into a hyphentated string using lower-case letters, packed
360-- | Convert a UUID into a hyphentated string using lower-case letters, packed
361-- as ASCII bytes into `B.ByteString`.
361-- as ASCII bytes into `B.ByteString`.
uuid-types/uuid-types.cabal+1−1
@@ -42,7 +42,7 @@ Library
42 , hashable (>= 1.1.1.0 && < 1.2)
42 , hashable (>= 1.1.1.0 && < 1.2)
43 || (>= 1.2.1 && < 1.3)
43 || (>= 1.2.1 && < 1.3)
44 , random >= 1.0.1 && < 1.2
44 , random >= 1.0.1 && < 1.2
45− , text >= 1 && < 1.3
45+ , text >= 1.2.3 && < 1.3
46
46
47 exposed-modules:
47 exposed-modules:
48 Data.UUID.Types
48 Data.UUID.Types