avoid unnecessary conversion from and back to ByteString

This commit is contained in:
Joey Hess 2019-01-14 12:40:13 -04:00
parent 52695e5925
commit ff0a2bee2d
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -65,15 +65,14 @@ hashDirs (HashLevels 1) sz s = addTrailingPathSeparator $ take sz s
hashDirs _ sz s = addTrailingPathSeparator $ take sz s </> drop sz s
hashDirLower :: HashLevels -> Hasher
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $
encodeBL $ key2file $ nonChunkKey k
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ key2file' $ nonChunkKey k
{- This was originally using Data.Hash.MD5 from MissingH. This new version
- is faster, but ugly as it has to replicate the 4 Word32's that produced. -}
hashDirMixed :: HashLevels -> Hasher
hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $
encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $
Utility.Hash.md5 $ encodeBL $ key2file $ nonChunkKey k
Utility.Hash.md5 $ key2file' $ nonChunkKey k
where
encodeWord32 (b1:b2:b3:b4:rest) =
(shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1)