on master help sign in
Optimise `toText` (~10x speedup) & `fromText` (~2x speedup)

Before: benchmarking conversion/toText time 1.007 μs (1.006 μs .. 1.009 μs) 1.000 R² (1.000 R² .. 1.000 R²) mean 1.007 μs (1.006 μs .. 1.009 μs) std dev 4.587 ns (3.262 ns .. 7.831 ns) benchmarking conversion/fromText time 888.2 ns (887.3 ns .. 889.4 ns) 1.000 R² (1.000 R² .. 1.000 R²) mean 887.9 ns (887.2 ns .. 888.8 ns) std dev 2.628 ns (1.886 ns .. 3.688 ns) After: benchmarking conversion/toText time 86.49 ns (86.19 ns .. 86.77 ns) 1.000 R² (1.000 R² .. 1.000 R²) mean 86.40 ns (86.18 ns .. 86.70 ns) std dev 824.7 ps (610.0 ps .. 1.281 ns) benchmarking conversion/fromText time 330.3 ns (328.3 ns .. 332.9 ns) 1.000 R² (1.000 R² .. 1.000 R²) mean 331.3 ns (329.9 ns .. 332.6 ns) std dev 4.434 ns (3.950 ns .. 5.143 ns)

commit023f84cf38e21980a1499233d36e67b391a288be authorHerbert Valerio Riedel <hvr@gnu.org> dateSun 1 Apr 2018, 21:39 (9 years ago) parente63a5cb
2 files changed+4−4
uuid-types/Data/UUID/Types/Internal.hs+3−3 uuid-types/uuid-types.cabal+1−1
uuid-types/Data/UUID/Types/Internal.hs+3−3
@@ -68,7 +68,7 @@ import qualified Data.ByteString.Internal as BI
6868import qualified Data.ByteString.Lazy as BL
6969import qualified Data.ByteString.Unsafe as BU
7070import Data.Text (Text)
71−import qualified Data.Text as T
71+import qualified Data.Text.Encoding as T
7272
7373import Data.UUID.Types.Internal.Builder
7474
@@ -351,11 +351,11 @@ toString uuid = hexw w0 $ hexw' w1 $ hexw' w2 $ hexw w3 ""
351351-- | If the passed in `Text` can be parsed as an ASCII representation of
352352-- a `UUID`, it will be. The hyphens may not be omitted.
353353fromText :: Text -> Maybe UUID
354−fromText = fromString . T.unpack
354+fromText = fromASCIIBytes . T.encodeUtf8
355355
356356-- | Convert a UUID into a hyphentated string using lower-case letters.
357357toText :: UUID -> Text
358−toText = T.pack . toString
358+toText = T.decodeLatin1 . toASCIIBytes
359359
360360-- | Convert a UUID into a hyphentated string using lower-case letters, packed
361361-- as ASCII bytes into `B.ByteString`.
uuid-types/uuid-types.cabal+1−1
@@ -42,7 +42,7 @@ Library
4242 , hashable (>= 1.1.1.0 && < 1.2)
4343 || (>= 1.2.1 && < 1.3)
4444 , random >= 1.0.1 && < 1.2
45− , text >= 1 && < 1.3
45+ , text >= 1.2.3 && < 1.3
4646
4747 exposed-modules:
4848 Data.UUID.Types