convert UUID from String to ByteString
This should make == comparison of UUIDs somewhat faster, and perhaps a few other operations around maps of UUIDs etc. FromUUID/ToUUID are used to convert String, which is still used for all IO of UUIDs. Eventually the hope is those instances can be removed, and all git-annex branch log files etc use ByteString throughout, for a real speed improvement. Note the use of fromRawFilePath / toRawFilePath -- while a UUID usually contains only alphanumerics and so could be treated as ascii, it's conceivable that some git-annex repository has been initialized using a UUID that is not only not a canonical UUID, but contains high unicode or invalid unicode. Using the filesystem encoding avoids any problems with such a thing. However, a NUL in a UUID seems extremely unlikely, so I didn't use encodeBS / decodeBS to avoid their extra overhead in handling NULs. The Read/Show instance for UUID luckily serializes the same way for ByteString as it did for String.
This commit is contained in:
parent
1f52e5c5cb
commit
9cc6d5549b
8 changed files with 39 additions and 18 deletions
|
@ -37,6 +37,7 @@ import Config
|
|||
import qualified Data.UUID as U
|
||||
import qualified Data.UUID.V4 as U4
|
||||
import qualified Data.UUID.V5 as U5
|
||||
import Data.String
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
configkey :: ConfigKey
|
||||
|
@ -44,13 +45,13 @@ configkey = annexConfig "uuid"
|
|||
|
||||
{- Generates a random UUID, that does not include the MAC address. -}
|
||||
genUUID :: IO UUID
|
||||
genUUID = UUID . show <$> U4.nextRandom
|
||||
genUUID = toUUID <$> U4.nextRandom
|
||||
|
||||
{- Generates a UUID from a given string, using a namespace.
|
||||
- Given the same namespace, the same string will always result
|
||||
- in the same UUID. -}
|
||||
genUUIDInNameSpace :: U.UUID -> String -> UUID
|
||||
genUUIDInNameSpace namespace = UUID . show . U5.generateNamed namespace . s2w8
|
||||
genUUIDInNameSpace namespace = toUUID . U5.generateNamed namespace . s2w8
|
||||
|
||||
{- Namespace used for UUIDs derived from git-remote-gcrypt ids. -}
|
||||
gCryptNameSpace :: U.UUID
|
||||
|
@ -117,8 +118,8 @@ setUUID r u = do
|
|||
|
||||
-- Dummy uuid for the whole web. Do not alter.
|
||||
webUUID :: UUID
|
||||
webUUID = UUID "00000000-0000-0000-0000-000000000001"
|
||||
webUUID = UUID (fromString "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
-- Dummy uuid for bittorrent. Do not alter.
|
||||
bitTorrentUUID :: UUID
|
||||
bitTorrentUUID = UUID "00000000-0000-0000-0000-000000000002"
|
||||
bitTorrentUUID = UUID (fromString "00000000-0000-0000-0000-000000000002")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue