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:
Anton-Latukha 2021-02-03 13:18:26 +02:00
parent f86235758a
commit e2378e0eea
No known key found for this signature in database
GPG Key ID: 3D84C07E91802E41
5 changed files with 7 additions and 7 deletions

View File

@ -22,7 +22,7 @@ digits32 = Vector.fromList "0123456789abcdfghijklmnpqrsvwxyz"
-- | Encode a 'BS.ByteString' in Nix's base32 encoding
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
-- Each base32 character gives us 5 bits of information, while
-- each byte gives is 8. Because 'div' rounds down, we need to add

View File

@ -218,7 +218,7 @@ instance (ValidAlgo a, KnownNat n) => ValidAlgo ('Truncated n a) where
truncateDigest
:: forall n a.(KnownNat n) => Digest a -> Digest ('Truncated n a)
truncateDigest (Digest c) =
Digest $ BS.pack $ map truncOutputByte [0.. n-1]
Digest $ BS.pack $ fmap truncOutputByte [0.. n-1]
where
n = fromIntegral $ natVal (Proxy @n)

View File

@ -41,7 +41,7 @@ makeTextPath
makeTextPath fp nm h refs = makeStorePath fp ty h nm
where
ty =
BS.intercalate ":" ("text" : map storePathToRawFilePath (HS.toList refs))
BS.intercalate ":" ("text" : fmap storePathToRawFilePath (HS.toList refs))
makeFixedOutputPath
:: forall hashAlgo

View File

@ -110,14 +110,14 @@ putText :: Text -> Put
putText = putByteStringLen . textToBSL
putTexts :: [Text] -> Put
putTexts = putByteStrings . map textToBSL
putTexts = putByteStrings . fmap textToBSL
getPath :: FilePath -> Get (Either String StorePath)
getPath sd = parsePath sd <$> getByteStringLen
getPaths :: FilePath -> Get StorePathSet
getPaths sd =
Data.HashSet.fromList . rights . map (parsePath sd) <$> getByteStrings
Data.HashSet.fromList . rights . fmap (parsePath sd) <$> getByteStrings
putPath :: StorePath -> Put
putPath = putByteStringLen . BSL.fromStrict . storePathToRawFilePath

View File

@ -108,9 +108,9 @@ enterNamespaces = do
gid <- getEffectiveGroupID
unshare [User, Network, Mount]
-- map our (parent) uid to root
-- fmap our (parent) uid to root
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
withNixDaemon