libexpr: prefer Value::str() over Value::c_str()

at call sites that already cast to string_view to take advantage of the
stored length

Change-Id: I525c68e83e1c71bdc5ad2c3ed0bd0863ad20aaf2
This commit is contained in:
Mel Zuser 2024-05-15 21:20:08 -07:00
parent a9f026f8b1
commit 947c509110
5 changed files with 6 additions and 6 deletions

View file

@ -264,7 +264,7 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
Value nameValue; Value nameValue;
name.expr->eval(state, env, nameValue); name.expr->eval(state, env, nameValue);
state.forceStringNoCtx(nameValue, name.expr->getPos(), "while evaluating an attribute name"); state.forceStringNoCtx(nameValue, name.expr->getPos(), "while evaluating an attribute name");
return state.symbols.create(nameValue.c_str()); return state.symbols.create(nameValue.str());
} }
} }
@ -1348,7 +1348,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
if (nameVal.type() == nNull) if (nameVal.type() == nNull)
continue; continue;
state.forceStringNoCtx(nameVal, i.pos, "while evaluating the name of a dynamic attribute"); state.forceStringNoCtx(nameVal, i.pos, "while evaluating the name of a dynamic attribute");
auto nameSym = state.symbols.create(nameVal.c_str()); auto nameSym = state.symbols.create(nameVal.str());
Bindings::iterator j = v.attrs->find(nameSym); Bindings::iterator j = v.attrs->find(nameSym);
if (j != v.attrs->end()) if (j != v.attrs->end())
state.error<EvalError>("dynamic attribute '%1%' already defined at %2%", state.symbols[nameSym], state.positions[j->pos]).atPos(i.pos).withFrame(env, *this).debugThrow(); state.error<EvalError>("dynamic attribute '%1%' already defined at %2%", state.symbols[nameSym], state.positions[j->pos]).atPos(i.pos).withFrame(env, *this).debugThrow();

View file

@ -122,7 +122,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
input.overrides = parseFlakeInputs(state, attr.value, attr.pos, baseDir, lockRootPath, depth + 1); input.overrides = parseFlakeInputs(state, attr.value, attr.pos, baseDir, lockRootPath, depth + 1);
} else if (attr.name == sFollows) { } else if (attr.name == sFollows) {
expectType(state, nString, *attr.value, attr.pos); expectType(state, nString, *attr.value, attr.pos);
auto follows(parseInputPath(attr.value->c_str())); auto follows(parseInputPath(attr.value->str()));
follows.insert(follows.begin(), lockRootPath.begin(), lockRootPath.end()); follows.insert(follows.begin(), lockRootPath.begin(), lockRootPath.end());
input.follows = follows; input.follows = follows;
} else { } else {

View file

@ -2590,7 +2590,7 @@ static void prim_removeAttrs(EvalState & state, const PosIdx pos, Value * * args
names.reserve(args[1]->listSize()); names.reserve(args[1]->listSize());
for (auto elem : args[1]->listItems()) { for (auto elem : args[1]->listItems()) {
state.forceStringNoCtx(*elem, pos, "while evaluating the values of the second argument passed to builtins.removeAttrs"); state.forceStringNoCtx(*elem, pos, "while evaluating the values of the second argument passed to builtins.removeAttrs");
names.emplace_back(state.symbols.create(elem->c_str()), nullptr); names.emplace_back(state.symbols.create(elem->str()), nullptr);
} }
std::sort(names.begin(), names.end()); std::sort(names.begin(), names.end());

View file

@ -28,7 +28,7 @@ void printAmbiguous(
printLiteralBool(str, v.boolean); printLiteralBool(str, v.boolean);
break; break;
case nString: case nString:
escapeString(str, v.c_str()); escapeString(str, v.str());
break; break;
case nPath: case nPath:
str << v.path().to_string(); // !!! escaping? str << v.path().to_string(); // !!! escaping?

View file

@ -200,7 +200,7 @@ private:
{ {
escapeString( escapeString(
output, output,
v.c_str(), v.str(),
{ {
.maxLength = options.maxStringLength, .maxLength = options.maxStringLength,
.outputAnsiColors = options.ansiColors, .outputAnsiColors = options.ansiColors,