mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-11-30 12:53:11 +03:00
Core, Remote: map -> fmap
Allow not only lists. This for example should allow NonEmpty lists at least. Also do not think I do this things on a whim. I did some research on: is there a reason to use map over fmap, and are the performance reasons? In short - there is 0 infornamation on why some people use `map` over `fmap`, there are no reports of performance reasons. Well, I know that there is a possibility of a minor type class interface compilation & runtime use cost. But I think GHC is good enough to infer zero cost for the concrete list type for which `map` gets used. And overall we not did thorough profiling/perfommans walkthrough so far. I am sure that use of standard fmap for code flexibility is not a bottleneck in the design, I've seen some performance problems design has. And we not even did the profiling to do inlining and specialize work yet. It is more effective to keep using `fmap`, and supply specialization, which allows to keep the code polymorhic, portable to write for and effective in performance.
This commit is contained in:
parent
f86235758a
commit
e2378e0eea
@ -22,7 +22,7 @@ digits32 = Vector.fromList "0123456789abcdfghijklmnpqrsvwxyz"
|
|||||||
|
|
||||||
-- | Encode a 'BS.ByteString' in Nix's base32 encoding
|
-- | Encode a 'BS.ByteString' in Nix's base32 encoding
|
||||||
encode :: ByteString -> Text
|
encode :: ByteString -> Text
|
||||||
encode c = Data.Text.pack $ map char32 [nChar - 1, nChar - 2 .. 0]
|
encode c = Data.Text.pack $ fmap char32 [nChar - 1, nChar - 2 .. 0]
|
||||||
where
|
where
|
||||||
-- Each base32 character gives us 5 bits of information, while
|
-- Each base32 character gives us 5 bits of information, while
|
||||||
-- each byte gives is 8. Because 'div' rounds down, we need to add
|
-- each byte gives is 8. Because 'div' rounds down, we need to add
|
||||||
|
@ -218,7 +218,7 @@ instance (ValidAlgo a, KnownNat n) => ValidAlgo ('Truncated n a) where
|
|||||||
truncateDigest
|
truncateDigest
|
||||||
:: forall n a.(KnownNat n) => Digest a -> Digest ('Truncated n a)
|
:: forall n a.(KnownNat n) => Digest a -> Digest ('Truncated n a)
|
||||||
truncateDigest (Digest c) =
|
truncateDigest (Digest c) =
|
||||||
Digest $ BS.pack $ map truncOutputByte [0.. n-1]
|
Digest $ BS.pack $ fmap truncOutputByte [0.. n-1]
|
||||||
where
|
where
|
||||||
n = fromIntegral $ natVal (Proxy @n)
|
n = fromIntegral $ natVal (Proxy @n)
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ makeTextPath
|
|||||||
makeTextPath fp nm h refs = makeStorePath fp ty h nm
|
makeTextPath fp nm h refs = makeStorePath fp ty h nm
|
||||||
where
|
where
|
||||||
ty =
|
ty =
|
||||||
BS.intercalate ":" ("text" : map storePathToRawFilePath (HS.toList refs))
|
BS.intercalate ":" ("text" : fmap storePathToRawFilePath (HS.toList refs))
|
||||||
|
|
||||||
makeFixedOutputPath
|
makeFixedOutputPath
|
||||||
:: forall hashAlgo
|
:: forall hashAlgo
|
||||||
|
@ -110,14 +110,14 @@ putText :: Text -> Put
|
|||||||
putText = putByteStringLen . textToBSL
|
putText = putByteStringLen . textToBSL
|
||||||
|
|
||||||
putTexts :: [Text] -> Put
|
putTexts :: [Text] -> Put
|
||||||
putTexts = putByteStrings . map textToBSL
|
putTexts = putByteStrings . fmap textToBSL
|
||||||
|
|
||||||
getPath :: FilePath -> Get (Either String StorePath)
|
getPath :: FilePath -> Get (Either String StorePath)
|
||||||
getPath sd = parsePath sd <$> getByteStringLen
|
getPath sd = parsePath sd <$> getByteStringLen
|
||||||
|
|
||||||
getPaths :: FilePath -> Get StorePathSet
|
getPaths :: FilePath -> Get StorePathSet
|
||||||
getPaths sd =
|
getPaths sd =
|
||||||
Data.HashSet.fromList . rights . map (parsePath sd) <$> getByteStrings
|
Data.HashSet.fromList . rights . fmap (parsePath sd) <$> getByteStrings
|
||||||
|
|
||||||
putPath :: StorePath -> Put
|
putPath :: StorePath -> Put
|
||||||
putPath = putByteStringLen . BSL.fromStrict . storePathToRawFilePath
|
putPath = putByteStringLen . BSL.fromStrict . storePathToRawFilePath
|
||||||
|
@ -108,9 +108,9 @@ enterNamespaces = do
|
|||||||
gid <- getEffectiveGroupID
|
gid <- getEffectiveGroupID
|
||||||
|
|
||||||
unshare [User, Network, Mount]
|
unshare [User, Network, Mount]
|
||||||
-- map our (parent) uid to root
|
-- fmap our (parent) uid to root
|
||||||
writeUserMappings Nothing [UserMapping 0 uid 1]
|
writeUserMappings Nothing [UserMapping 0 uid 1]
|
||||||
-- map our (parent) gid to root group
|
-- fmap our (parent) gid to root group
|
||||||
writeGroupMappings Nothing [GroupMapping 0 gid 1] True
|
writeGroupMappings Nothing [GroupMapping 0 gid 1] True
|
||||||
|
|
||||||
withNixDaemon
|
withNixDaemon
|
||||||
|
Loading…
Reference in New Issue
Block a user