diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-07-26 14:29:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 14:29:03 +0200 |
commit | da552104030fb294ca547f26113e3fb7f796877b (patch) | |
tree | 50455db4d6219f468dbcdbb958795720a3f70f6d /src | |
parent | 97be92569ca8294a8bc0977cb59ce7dcbdbc6c36 (diff) | |
parent | c1c5dd7449d54dbec48dccd26f3b3fb09e26b290 (diff) |
Merge pull request #5037 from Pamplemousse/less_globals
Avoid global counters
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/eval.cc | 16 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 7 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c3206a577..419b377ba 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -854,39 +854,37 @@ Value * Expr::maybeThunk(EvalState & state, Env & env) } -unsigned long nrAvoided = 0; - Value * ExprVar::maybeThunk(EvalState & state, Env & env) { Value * v = state.lookupVar(&env, *this, true); /* The value might not be initialised in the environment yet. In that case, ignore it. */ - if (v) { nrAvoided++; return v; } + if (v) { state.nrAvoided++; return v; } return Expr::maybeThunk(state, env); } Value * ExprString::maybeThunk(EvalState & state, Env & env) { - nrAvoided++; + state.nrAvoided++; return &v; } Value * ExprInt::maybeThunk(EvalState & state, Env & env) { - nrAvoided++; + state.nrAvoided++; return &v; } Value * ExprFloat::maybeThunk(EvalState & state, Env & env) { - nrAvoided++; + state.nrAvoided++; return &v; } Value * ExprPath::maybeThunk(EvalState & state, Env & env) { - nrAvoided++; + state.nrAvoided++; return &v; } @@ -1141,8 +1139,6 @@ static string showAttrPath(EvalState & state, Env & env, const AttrPath & attrPa } -unsigned long nrLookups = 0; - void ExprSelect::eval(EvalState & state, Env & env, Value & v) { Value vTmp; @@ -1154,7 +1150,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) try { for (auto & i : attrPath) { - nrLookups++; + state.nrLookups++; Bindings::iterator j; Symbol name = getName(i, state, env); if (def) { diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index e3eaed6d3..47db8b2ba 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -316,8 +316,10 @@ private: unsigned long nrValuesInEnvs = 0; unsigned long nrValues = 0; unsigned long nrListElems = 0; + unsigned long nrLookups = 0; unsigned long nrAttrsets = 0; unsigned long nrAttrsInAttrsets = 0; + unsigned long nrAvoided = 0; unsigned long nrOpUpdates = 0; unsigned long nrOpUpdateValuesCopied = 0; unsigned long nrListConcats = 0; @@ -339,6 +341,11 @@ private: friend struct ExprOpUpdate; friend struct ExprOpConcatLists; + friend struct ExprVar; + friend struct ExprString; + friend struct ExprInt; + friend struct ExprFloat; + friend struct ExprPath; friend struct ExprSelect; friend void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v); friend void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v); |