1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

Fix JSON_IMPL macro to avoid extraneous copies

Should take the thing we're serializing by reference.
This commit is contained in:
John Ericson 2025-09-23 13:05:12 -04:00
parent d9de675357
commit af71a9dbd9
7 changed files with 17 additions and 17 deletions

View file

@ -509,7 +509,7 @@ fetchers::PublicKey adl_serializer<fetchers::PublicKey>::from_json(const json &
return res; return res;
} }
void adl_serializer<fetchers::PublicKey>::to_json(json & json, fetchers::PublicKey p) void adl_serializer<fetchers::PublicKey>::to_json(json & json, const fetchers::PublicKey & p)
{ {
json["type"] = p.type; json["type"] = p.type;
json["key"] = p.key; json["key"] = p.key;

View file

@ -356,7 +356,7 @@ DerivationOptions adl_serializer<DerivationOptions>::from_json(const json & json
}; };
} }
void adl_serializer<DerivationOptions>::to_json(json & json, DerivationOptions o) void adl_serializer<DerivationOptions>::to_json(json & json, const DerivationOptions & o)
{ {
json["outputChecks"] = std::visit( json["outputChecks"] = std::visit(
overloaded{ overloaded{
@ -398,7 +398,7 @@ DerivationOptions::OutputChecks adl_serializer<DerivationOptions::OutputChecks>:
}; };
} }
void adl_serializer<DerivationOptions::OutputChecks>::to_json(json & json, DerivationOptions::OutputChecks c) void adl_serializer<DerivationOptions::OutputChecks>::to_json(json & json, const DerivationOptions::OutputChecks & c)
{ {
json["ignoreSelfRefs"] = c.ignoreSelfRefs; json["ignoreSelfRefs"] = c.ignoreSelfRefs;
json["allowedReferences"] = c.allowedReferences; json["allowedReferences"] = c.allowedReferences;

View file

@ -1494,7 +1494,7 @@ Derivation adl_serializer<Derivation>::from_json(const json & json)
return Derivation::fromJSON(json); return Derivation::fromJSON(json);
} }
void adl_serializer<Derivation>::to_json(json & json, Derivation c) void adl_serializer<Derivation>::to_json(json & json, const Derivation & c)
{ {
json = c.toJSON(); json = c.toJSON();
} }

View file

@ -150,7 +150,7 @@ OutputsSpec adl_serializer<OutputsSpec>::from_json(const json & json)
return OutputsSpec::Names{std::move(names)}; return OutputsSpec::Names{std::move(names)};
} }
void adl_serializer<OutputsSpec>::to_json(json & json, OutputsSpec t) void adl_serializer<OutputsSpec>::to_json(json & json, const OutputsSpec & t)
{ {
std::visit( std::visit(
overloaded{ overloaded{
@ -169,7 +169,7 @@ ExtendedOutputsSpec adl_serializer<ExtendedOutputsSpec>::from_json(const json &
} }
} }
void adl_serializer<ExtendedOutputsSpec>::to_json(json & json, ExtendedOutputsSpec t) void adl_serializer<ExtendedOutputsSpec>::to_json(json & json, const ExtendedOutputsSpec & t)
{ {
std::visit( std::visit(
overloaded{ overloaded{

View file

@ -88,7 +88,7 @@ StorePath adl_serializer<StorePath>::from_json(const json & json)
return StorePath{getString(json)}; return StorePath{getString(json)};
} }
void adl_serializer<StorePath>::to_json(json & json, StorePath storePath) void adl_serializer<StorePath>::to_json(json & json, const StorePath & storePath)
{ {
json = storePath.to_string(); json = storePath.to_string();
} }

View file

@ -165,7 +165,7 @@ Realisation adl_serializer<Realisation>::from_json(const json & json0)
}; };
} }
void adl_serializer<Realisation>::to_json(json & json, Realisation r) void adl_serializer<Realisation>::to_json(json & json, const Realisation & r)
{ {
auto jsonDependentRealisations = nlohmann::json::object(); auto jsonDependentRealisations = nlohmann::json::object();
for (auto & [depId, depOutPath] : r.dependentRealisations) for (auto & [depId, depOutPath] : r.dependentRealisations)

View file

@ -11,6 +11,6 @@
struct adl_serializer<TYPE> \ struct adl_serializer<TYPE> \
{ \ { \
static TYPE from_json(const json & json); \ static TYPE from_json(const json & json); \
static void to_json(json & json, TYPE t); \ static void to_json(json & json, const TYPE & t); \
}; \ }; \
} }