convert serializeKey' to strict ByteString
The builder produces a lazy ByteString, and L.toStrict has to copy it, but needing to use the builder is no longer to common case; the serialization will normally be cached already as a strict ByteString, and this avoids keyFile' needing to use L.toStrict . serializeKey'
This commit is contained in:
parent
4536c93bb2
commit
e0c4ac99b5
5 changed files with 23 additions and 15 deletions
21
Key.hs
21
Key.hs
|
@ -56,11 +56,13 @@ stubKey = Key
|
|||
|
||||
-- Gets the parent of a chunk key.
|
||||
nonChunkKey :: Key -> Key
|
||||
nonChunkKey k = k
|
||||
{ keyChunkSize = Nothing
|
||||
, keyChunkNum = Nothing
|
||||
, keySerialization = Nothing
|
||||
}
|
||||
nonChunkKey k
|
||||
| keyChunkSize k == Nothing && keyChunkNum k == Nothing = k
|
||||
| otherwise = k
|
||||
{ keyChunkSize = Nothing
|
||||
, keyChunkNum = Nothing
|
||||
, keySerialization = Nothing
|
||||
}
|
||||
|
||||
-- Where a chunk key is offset within its parent.
|
||||
chunkKeyOffset :: Key -> Maybe Integer
|
||||
|
@ -96,12 +98,13 @@ buildKey k = byteString (formatKeyVariety (keyVariety k))
|
|||
_ ?: Nothing = mempty
|
||||
|
||||
serializeKey :: Key -> String
|
||||
serializeKey = decodeBL' . serializeKey'
|
||||
serializeKey = decodeBS' . serializeKey'
|
||||
|
||||
serializeKey' :: Key -> L.ByteString
|
||||
serializeKey' :: Key -> S.ByteString
|
||||
serializeKey' k = case keySerialization k of
|
||||
Nothing -> toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty (buildKey k)
|
||||
Just b -> L.fromStrict b
|
||||
Nothing -> L.toStrict $
|
||||
toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty (buildKey k)
|
||||
Just b -> b
|
||||
|
||||
{- This is a strict parser for security reasons; a key
|
||||
- can contain only 4 fields, which all consist only of numbers.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue