Pass stuff by reference

This commit is contained in:
Eelco Dolstra 2019-04-16 14:27:54 +02:00
parent e1d73edb10
commit 7b312a8762
2 changed files with 13 additions and 11 deletions

View file

@ -34,7 +34,7 @@ std::shared_ptr<FlakeRegistry> readRegistry(const Path & path)
} }
/* Write a registry to a file. */ /* Write a registry to a file. */
void writeRegistry(const FlakeRegistry & registry, Path path) void writeRegistry(const FlakeRegistry & registry, const Path & path)
{ {
nlohmann::json json; nlohmann::json json;
json["version"] = 1; json["version"] = 1;
@ -99,7 +99,7 @@ LockFile readLockFile(const Path & path)
return lockFile; return lockFile;
} }
nlohmann::json flakeEntryToJson(LockFile::FlakeEntry & entry) nlohmann::json flakeEntryToJson(const LockFile::FlakeEntry & entry)
{ {
nlohmann::json json; nlohmann::json json;
json["uri"] = entry.ref.to_string(); json["uri"] = entry.ref.to_string();
@ -110,7 +110,7 @@ nlohmann::json flakeEntryToJson(LockFile::FlakeEntry & entry)
return json; return json;
} }
void writeLockFile(LockFile lockFile, Path path) void writeLockFile(const LockFile & lockFile, const Path & path)
{ {
nlohmann::json json; nlohmann::json json;
json["version"] = 1; json["version"] = 1;
@ -156,7 +156,8 @@ const std::vector<std::shared_ptr<FlakeRegistry>> EvalState::getFlakeRegistries(
} }
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
std::vector<std::shared_ptr<FlakeRegistry>> registries, std::vector<FlakeRef> pastSearches = {}) const std::vector<std::shared_ptr<FlakeRegistry>> & registries,
std::vector<FlakeRef> pastSearches = {})
{ {
for (std::shared_ptr<FlakeRegistry> registry : registries) { for (std::shared_ptr<FlakeRegistry> registry : registries) {
auto i = registry->entries.find(flakeRef); auto i = registry->entries.find(flakeRef);
@ -362,14 +363,14 @@ Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef, bool impur
return deps; return deps;
} }
LockFile::FlakeEntry dependenciesToFlakeEntry(Dependencies & deps) LockFile::FlakeEntry dependenciesToFlakeEntry(const Dependencies & deps)
{ {
LockFile::FlakeEntry entry(deps.flake.ref); LockFile::FlakeEntry entry(deps.flake.ref);
for (Dependencies & deps : deps.flakeDeps) for (auto & deps : deps.flakeDeps)
entry.flakeEntries.insert_or_assign(deps.flake.id, dependenciesToFlakeEntry(deps)); entry.flakeEntries.insert_or_assign(deps.flake.id, dependenciesToFlakeEntry(deps));
for (NonFlake & nonFlake : deps.nonFlakeDeps) for (auto & nonFlake : deps.nonFlakeDeps)
entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonFlake.ref); entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonFlake.ref);
return entry; return entry;
@ -385,7 +386,7 @@ LockFile getLockFile(EvalState & evalState, FlakeRef & flakeRef)
return lockFile; return lockFile;
} }
void updateLockFile(EvalState & state, Path path) void updateLockFile(EvalState & state, const Path & path)
{ {
// 'path' is the path to the local flake repo. // 'path' is the path to the local flake repo.
FlakeRef flakeRef = FlakeRef("file://" + path); FlakeRef flakeRef = FlakeRef("file://" + path);

View file

@ -33,7 +33,7 @@ void makeFlakeValue(EvalState & state, const FlakeRef & flakeRef, bool impureTop
std::shared_ptr<FlakeRegistry> readRegistry(const Path &); std::shared_ptr<FlakeRegistry> readRegistry(const Path &);
void writeRegistry(const FlakeRegistry &, Path); void writeRegistry(const FlakeRegistry &, const Path &);
struct Flake struct Flake
{ {
@ -75,7 +75,8 @@ struct Dependencies
Dependencies resolveFlake(EvalState &, const FlakeRef &, bool impureTopRef, bool isTopFlake = true); Dependencies resolveFlake(EvalState &, const FlakeRef &, bool impureTopRef, bool isTopFlake = true);
FlakeRegistry updateLockFile(EvalState &, Flake &); FlakeRegistry updateLockFile(EvalState &, const Flake &);
void updateLockFile(EvalState &, const Path & path);
void updateLockFile(EvalState &, Path path);
} }