Make EvalState::inputAccessors keyed by the accessor number

This commit is contained in:
Eelco Dolstra 2022-08-29 15:35:35 +02:00
parent f95c425db1
commit 30be6445e6
3 changed files with 7 additions and 11 deletions

View file

@ -135,21 +135,15 @@ std::pair<SourcePath, uint32_t> findPackageFilename(EvalState & state, Value & v
size_t number = std::stoi(std::string(pos, 0, slash));
pos = pos.substr(slash);
std::shared_ptr<InputAccessor> accessor;
for (auto & i : state.inputAccessors)
if (i.second->number == number) {
accessor = i.second;
break;
}
if (!accessor) fail();
auto accessor = state.inputAccessors.find(number);
if (accessor == state.inputAccessors.end()) fail();
auto colon = pos.rfind(':');
if (colon == std::string::npos) fail();
std::string filename(pos, 0, colon);
auto lineno = std::stoi(std::string(pos, colon + 1, std::string::npos));
return {SourcePath{ref(accessor), CanonPath(filename)}, lineno};
return {SourcePath{accessor->second, CanonPath(filename)}, lineno};
} catch (std::invalid_argument & e) {
fail();

View file

@ -114,7 +114,9 @@ public:
const SourcePath derivationInternal;
std::unordered_map<InputAccessor *, ref<InputAccessor>> inputAccessors;
/* A map keyed by InputAccessor::number that keeps input accessors
alive. */
std::unordered_map<size_t, ref<InputAccessor>> inputAccessors;
/* Store used to materialise .drv files. */
const ref<Store> store;

View file

@ -11,7 +11,7 @@ SourcePath EvalState::rootPath(const Path & path)
void EvalState::registerAccessor(ref<InputAccessor> accessor)
{
inputAccessors.emplace(&*accessor, accessor);
inputAccessors.emplace(accessor->number, accessor);
}
}