From 105d8ceb36a40e7ac9eeef43a2aae393025e4911 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 27 Nov 2024 02:09:08 +0100 Subject: [PATCH] libexpr: remove templated forceAttrs the callback is always called immediately, which defeats the purpose of the callback and the purpose of the template itself. there seems to not be any performance impact of this. optimizing Value::determinePos would be nice, but it's not used nearly often enough to matter at this point. Change-Id: I2aec6a38103630652112f4b273653f11d2404c04 --- lix/libcmd/repl.cc | 2 +- lix/libexpr/eval-inline.hh | 9 --------- lix/libexpr/eval.cc | 2 +- lix/libexpr/eval.hh | 4 ---- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index 782175098..f8f994479 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -1036,7 +1036,7 @@ Value * NixRepl::replInitInfo() void NixRepl::addAttrsToScope(Value & attrs) { - state.forceAttrs(attrs, [&]() { return attrs.determinePos(noPos); }, "while evaluating an attribute set to be merged in the global scope"); + state.forceAttrs(attrs, attrs.determinePos(noPos), "while evaluating an attribute set to be merged in the global scope"); if (displ + attrs.attrs->size() >= envSize) throw Error("environment full; cannot add more variables"); diff --git a/lix/libexpr/eval-inline.hh b/lix/libexpr/eval-inline.hh index 07605f6b7..38b5c84d4 100644 --- a/lix/libexpr/eval-inline.hh +++ b/lix/libexpr/eval-inline.hh @@ -89,15 +89,6 @@ void EvalState::forceValue(Value & v, const PosIdx pos) [[gnu::always_inline]] inline void EvalState::forceAttrs(Value & v, const PosIdx pos, std::string_view errorCtx) { - forceAttrs(v, [&]() { return pos; }, errorCtx); -} - - -template -[[gnu::always_inline]] -inline void EvalState::forceAttrs(Value & v, Callable getPos, std::string_view errorCtx) -{ - PosIdx pos = getPos(); forceValue(v, pos); if (v.type() != nAttrs) { error( diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 26021a509..aaeb72e37 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -1099,7 +1099,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v) Hence we need __overrides.) */ if (hasOverrides) { Value * vOverrides = (*v.attrs)[overrides->second.displ].value; - state.forceAttrs(*vOverrides, [&]() { return vOverrides->determinePos(noPos); }, "while evaluating the `__overrides` attribute"); + state.forceAttrs(*vOverrides, vOverrides->determinePos(noPos), "while evaluating the `__overrides` attribute"); Bindings * newBnds = state.mem.allocBindings(v.attrs->capacity() + vOverrides->attrs->size()); for (auto & i : *v.attrs) newBnds->push_back(i); diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 27dad80bc..808e445ee 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -476,10 +476,6 @@ public: bool forceBool(Value & v, const PosIdx pos, std::string_view errorCtx); void forceAttrs(Value & v, const PosIdx pos, std::string_view errorCtx); - - template - inline void forceAttrs(Value & v, Callable getPos, std::string_view errorCtx); - inline void forceList(Value & v, const PosIdx pos, std::string_view errorCtx); /** * @param v either lambda or primop