mirror of
https://github.com/NixOS/nix
synced 2025-06-24 18:01:16 +02:00
Merge pull request #13388 from NaN-git/opt-string_view
libexpr: further removal of `std::string` copies
This commit is contained in:
commit
6a74590063
1 changed files with 11 additions and 11 deletions
|
@ -1180,7 +1180,7 @@ static void prim_second(EvalState & state, const PosIdx pos, Value * * args, Val
|
||||||
|
|
||||||
static void derivationStrictInternal(
|
static void derivationStrictInternal(
|
||||||
EvalState & state,
|
EvalState & state,
|
||||||
const std::string & name,
|
std::string_view name,
|
||||||
const Bindings * attrs,
|
const Bindings * attrs,
|
||||||
Value & v);
|
Value & v);
|
||||||
|
|
||||||
|
@ -1200,7 +1200,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
|
||||||
/* Figure out the name first (for stack backtraces). */
|
/* Figure out the name first (for stack backtraces). */
|
||||||
auto nameAttr = state.getAttr(state.sName, attrs, "in the attrset passed as argument to builtins.derivationStrict");
|
auto nameAttr = state.getAttr(state.sName, attrs, "in the attrset passed as argument to builtins.derivationStrict");
|
||||||
|
|
||||||
std::string drvName;
|
std::string_view drvName;
|
||||||
try {
|
try {
|
||||||
drvName = state.forceStringNoCtx(*nameAttr->value, pos, "while evaluating the `name` attribute passed to builtins.derivationStrict");
|
drvName = state.forceStringNoCtx(*nameAttr->value, pos, "while evaluating the `name` attribute passed to builtins.derivationStrict");
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
@ -1259,7 +1259,7 @@ static void checkDerivationName(EvalState & state, std::string_view drvName)
|
||||||
|
|
||||||
static void derivationStrictInternal(
|
static void derivationStrictInternal(
|
||||||
EvalState & state,
|
EvalState & state,
|
||||||
const std::string & drvName,
|
std::string_view drvName,
|
||||||
const Bindings * attrs,
|
const Bindings * attrs,
|
||||||
Value & v)
|
Value & v)
|
||||||
{
|
{
|
||||||
|
@ -1899,7 +1899,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto rewrites = state.realiseContext(context);
|
auto rewrites = state.realiseContext(context);
|
||||||
path = rewriteStrings(path, rewrites);
|
path = rewriteStrings(std::move(path), rewrites);
|
||||||
} catch (InvalidPathError & e) {
|
} catch (InvalidPathError & e) {
|
||||||
state.error<EvalError>(
|
state.error<EvalError>(
|
||||||
"cannot find '%1%', since path '%2%' is not valid",
|
"cannot find '%1%', since path '%2%' is not valid",
|
||||||
|
@ -1909,8 +1909,8 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
}
|
}
|
||||||
|
|
||||||
lookupPath.elements.emplace_back(LookupPath::Elem {
|
lookupPath.elements.emplace_back(LookupPath::Elem {
|
||||||
.prefix = LookupPath::Prefix { .s = prefix },
|
.prefix = LookupPath::Prefix { .s = std::move(prefix) },
|
||||||
.path = LookupPath::Path { .s = path },
|
.path = LookupPath::Path { .s = std::move(path) },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2375,8 +2375,8 @@ static RegisterPrimOp primop_fromJSON({
|
||||||
static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
std::string name(state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.toFile"));
|
auto name = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.toFile");
|
||||||
std::string contents(state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.toFile"));
|
auto contents = state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.toFile");
|
||||||
|
|
||||||
StorePathSet refs;
|
StorePathSet refs;
|
||||||
|
|
||||||
|
@ -2633,7 +2633,7 @@ static RegisterPrimOp primop_filterSource({
|
||||||
static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
std::optional<SourcePath> path;
|
std::optional<SourcePath> path;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
Value * filterFun = nullptr;
|
Value * filterFun = nullptr;
|
||||||
auto method = ContentAddressMethod::Raw::NixArchive;
|
auto method = ContentAddressMethod::Raw::NixArchive;
|
||||||
std::optional<Hash> expectedHash;
|
std::optional<Hash> expectedHash;
|
||||||
|
@ -4593,12 +4593,12 @@ static void prim_replaceStrings(EvalState & state, const PosIdx pos, Value * * a
|
||||||
"'from' and 'to' arguments passed to builtins.replaceStrings have different lengths"
|
"'from' and 'to' arguments passed to builtins.replaceStrings have different lengths"
|
||||||
).atPos(pos).debugThrow();
|
).atPos(pos).debugThrow();
|
||||||
|
|
||||||
std::vector<std::string> from;
|
std::vector<std::string_view> from;
|
||||||
from.reserve(args[0]->listSize());
|
from.reserve(args[0]->listSize());
|
||||||
for (auto elem : args[0]->listItems())
|
for (auto elem : args[0]->listItems())
|
||||||
from.emplace_back(state.forceString(*elem, pos, "while evaluating one of the strings to replace passed to builtins.replaceStrings"));
|
from.emplace_back(state.forceString(*elem, pos, "while evaluating one of the strings to replace passed to builtins.replaceStrings"));
|
||||||
|
|
||||||
std::unordered_map<size_t, std::string> cache;
|
std::unordered_map<size_t, std::string_view> cache;
|
||||||
auto to = args[1]->listItems();
|
auto to = args[1]->listItems();
|
||||||
|
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue