mirror of
https://github.com/NixOS/nix
synced 2025-06-26 11:41:15 +02:00
return string_views from forceString*
once a string has been forced we already have dynamic storage allocated for it, so we can easily reuse that storage instead of copying.
This commit is contained in:
parent
0d7fae6a57
commit
41d70a2fc8
19 changed files with 94 additions and 87 deletions
|
@ -1857,7 +1857,7 @@ void EvalState::forceFunction(Value & v, const Pos & pos)
|
|||
}
|
||||
|
||||
|
||||
string EvalState::forceString(Value & v, const Pos & pos)
|
||||
std::string_view EvalState::forceString(Value & v, const Pos & pos)
|
||||
{
|
||||
forceValue(v, pos);
|
||||
if (v.type() != nString) {
|
||||
|
@ -1866,7 +1866,7 @@ string EvalState::forceString(Value & v, const Pos & pos)
|
|||
else
|
||||
throwTypeError("value is %1% while a string was expected", v);
|
||||
}
|
||||
return string(v.string.s);
|
||||
return v.string.s;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1901,17 +1901,17 @@ std::vector<std::pair<Path, std::string>> Value::getContext()
|
|||
}
|
||||
|
||||
|
||||
string EvalState::forceString(Value & v, PathSet & context, const Pos & pos)
|
||||
std::string_view EvalState::forceString(Value & v, PathSet & context, const Pos & pos)
|
||||
{
|
||||
string s = forceString(v, pos);
|
||||
auto s = forceString(v, pos);
|
||||
copyContext(v, context);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
string EvalState::forceStringNoCtx(Value & v, const Pos & pos)
|
||||
std::string_view EvalState::forceStringNoCtx(Value & v, const Pos & pos)
|
||||
{
|
||||
string s = forceString(v, pos);
|
||||
auto s = forceString(v, pos);
|
||||
if (v.string.context) {
|
||||
if (pos)
|
||||
throwEvalError(pos, "the string '%1%' is not allowed to refer to a store path (such as '%2%')",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue