diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-16 14:03:26 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-16 14:03:26 +0000 |
commit | 8ca4a001cb9e8ca2556c26a1b559b0322a8fb46a (patch) | |
tree | 2f068d0f0e4e4ff6cb29e01e2859c8d099c34eaa | |
parent | 497e4ad12650e27ecbaf0e056fe0c54bc12a138b (diff) |
* Improve sharing a bit.
-rw-r--r-- | src/libexpr/eval.cc | 11 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 89534688e..ce466ded4 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -652,15 +652,18 @@ void ExprWith::eval(EvalState & state, Env & env, Value & v) /* Because the first `with' may be a shallow copy of another attribute set (through a tCopy node), we need to clone its `attrs' before modifying them. */ - env2.values[0].attrs = new Bindings(*env2.values[0].attrs); + Bindings * old(env2.values[0].attrs); + state.mkAttrs(env2.values[0]); + foreach (Bindings::iterator, i, *old) + mkCopy((*env2.values[0].attrs)[i->first], i->second); foreach (Bindings::iterator, i, *env3->values[0].attrs) { Bindings::iterator j = env2.values[0].attrs->find(i->first); if (j == env2.values[0].attrs->end()) - (*env2.values[0].attrs)[i->first] = i->second; // !!! sharing + mkCopy((*env2.values[0].attrs)[i->first], i->second); } } - + state.eval(env2, body, v); } @@ -731,7 +734,7 @@ void ExprOpUpdate::eval(EvalState & state, Env & env, Value & v) state.forceAttrs(v2); foreach (Bindings::iterator, i, *v2.attrs) - (*v.attrs)[i->first] = i->second; // !!! sharing + mkCopy((*v.attrs)[i->first], i->second); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ae17506ce..c4495e81d 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -733,7 +733,7 @@ static void prim_listToAttrs(EvalState & state, Value * * args, Value & v) if (j == v2.attrs->end()) throw TypeError("`value' attribute missing in a call to `listToAttrs'"); - (*v.attrs)[state.symbols.create(name)] = j->second; // !!! sharing? + mkCopy((*v.attrs)[state.symbols.create(name)], j->second); } } |