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

SymbolStr: Remove std::string conversion

This refactoring allows the symbol table to be stored as something
other than std::strings.
This commit is contained in:
Eelco Dolstra 2024-06-06 16:33:41 +02:00
parent 0363dbf2b9
commit 61080554ab
15 changed files with 37 additions and 37 deletions

View file

@ -76,7 +76,7 @@ std::pair<Value *, PosIdx> findAlongAttrPath(EvalState & state, const std::strin
if (!a) {
std::set<std::string> attrNames;
for (auto & attr : *v->attrs())
attrNames.insert(state.symbols[attr.name]);
attrNames.insert(std::string(state.symbols[attr.name]));
auto suggestions = Suggestions::bestMatches(attrNames, attr);
throw AttrPathNotFound(suggestions, "attribute '%1%' in selection path '%2%' not found", attr, attrPath);

View file

@ -484,7 +484,7 @@ Suggestions AttrCursor::getSuggestionsForAttr(Symbol name)
auto attrNames = getAttrs();
std::set<std::string> strAttrNames;
for (auto & name : attrNames)
strAttrNames.insert(root->state.symbols[name]);
strAttrNames.insert(std::string(root->state.symbols[name]));
return Suggestions::bestMatches(strAttrNames, root->state.symbols[name]);
}

View file

@ -633,11 +633,11 @@ void mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const En
if (se.isWith && !env.values[0]->isThunk()) {
// add 'with' bindings.
for (auto & j : *env.values[0]->attrs())
vm[st[j.name]] = j.value;
vm.insert_or_assign(std::string(st[j.name]), j.value);
} else {
// iterate through staticenv bindings and add them.
for (auto & i : se.vars)
vm[st[i.first]] = env.values[i.second];
vm.insert_or_assign(std::string(st[i.first]), env.values[i.second]);
}
}
}
@ -1338,7 +1338,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
if (!(j = vAttrs->attrs()->get(name))) {
std::set<std::string> allAttrNames;
for (auto & attr : *vAttrs->attrs())
allAttrNames.insert(state.symbols[attr.name]);
allAttrNames.insert(std::string(state.symbols[attr.name]));
auto suggestions = Suggestions::bestMatches(allAttrNames, state.symbols[name]);
state.error<EvalError>("attribute '%1%' missing", state.symbols[name])
.atPos(pos).withSuggestions(suggestions).withFrame(env, *this).debugThrow();
@ -1496,7 +1496,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
if (!lambda.formals->has(i.name)) {
std::set<std::string> formalNames;
for (auto & formal : lambda.formals->formals)
formalNames.insert(symbols[formal.name]);
formalNames.insert(std::string(symbols[formal.name]));
auto suggestions = Suggestions::bestMatches(formalNames, symbols[i.name]);
error<TypeError>("function '%1%' called with unexpected argument '%2%'",
(lambda.name ? std::string(symbols[lambda.name]) : "anonymous lambda"),

View file

@ -342,9 +342,9 @@ std::optional<PackageInfo> getDerivation(EvalState & state, Value & v,
}
static std::string addToPath(const std::string & s1, const std::string & s2)
static std::string addToPath(const std::string & s1, std::string_view s2)
{
return s1.empty() ? s2 : s1 + "." + s2;
return s1.empty() ? std::string(s2) : s1 + "." + s2;
}

View file

@ -1225,7 +1225,7 @@ static void derivationStrictInternal(
for (auto & i : attrs->lexicographicOrder(state.symbols)) {
if (i->name == state.sIgnoreNulls) continue;
const std::string & key = state.symbols[i->name];
auto key = state.symbols[i->name];
vomit("processing attribute '%1%'", key);
auto handleHashMode = [&](const std::string_view s) {
@ -1309,7 +1309,7 @@ static void derivationStrictInternal(
if (i->name == state.sStructuredAttrs) continue;
(*jsonObject)[key] = printValueAsJSON(state, true, *i->value, pos, context);
jsonObject->emplace(key, printValueAsJSON(state, true, *i->value, pos, context));
if (i->name == state.sBuilder)
drv.builder = state.forceString(*i->value, context, pos, context_below);

View file

@ -30,9 +30,9 @@ public:
return *s == s2;
}
operator const std::string & () const
const char * c_str() const
{
return *s;
return s->c_str();
}
operator const std::string_view () const

View file

@ -58,7 +58,7 @@ json printValueAsJSON(EvalState & state, bool strict,
out = json::object();
for (auto & a : v.attrs()->lexicographicOrder(state.symbols)) {
try {
out[state.symbols[a->name]] = printValueAsJSON(state, strict, *a->value, a->pos, context, copyToStore);
out.emplace(state.symbols[a->name], printValueAsJSON(state, strict, *a->value, a->pos, context, copyToStore));
} catch (Error & e) {
e.addTrace(state.positions[a->pos],
HintFmt("while evaluating attribute '%1%'", state.symbols[a->name]));

View file

@ -9,7 +9,7 @@
namespace nix {
static XMLAttrs singletonAttrs(const std::string & name, const std::string & value)
static XMLAttrs singletonAttrs(const std::string & name, std::string_view value)
{
XMLAttrs attrs;
attrs[name] = value;