mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #14054 from obsidiansystems/to-json-no-copy
Fix `JSON_IMPL` macro to avoid extraneous copies
This commit is contained in:
commit
73d3ab05b6
7 changed files with 17 additions and 17 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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{
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
|
||||||
// Following https://github.com/nlohmann/json#how-can-i-use-get-for-non-default-constructiblenon-copyable-types
|
// Following https://github.com/nlohmann/json#how-can-i-use-get-for-non-default-constructiblenon-copyable-types
|
||||||
#define JSON_IMPL(TYPE) \
|
#define JSON_IMPL(TYPE) \
|
||||||
namespace nlohmann { \
|
namespace nlohmann { \
|
||||||
using namespace nix; \
|
using namespace nix; \
|
||||||
template<> \
|
template<> \
|
||||||
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); \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue