about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-21T18·20+0100
committerVincent Ambo <tazjin@google.com>2020-05-21T18·21+0100
commit28e347effe1ba4325fc485e920bda45c838e0450 (patch)
treede476a8bd0138bce979c14bab45c6f22714585a1 /third_party/nix/src/libexpr/eval.cc
parent1bb9cd7749748ee7019efcde834bbdb2b56e68e1 (diff)
refactor(3p/nix/libexpr): Use absl::btree_map for AttrSets r/799
This is the first step towards replacing the implementation of
attribute sets with an absl::btree_map.

Currently many access are done using array offsets and pointer
arithmetic, so this change is currently causing Nix to fail in various
ways.
Diffstat (limited to 'third_party/nix/src/libexpr/eval.cc')
-rw-r--r--third_party/nix/src/libexpr/eval.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 875dab2ee7..760bada7b0 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -827,7 +827,8 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
     env2.up = &env;
     dynamicEnv = &env2;
 
-    auto overrides = attrs.find(state.sOverrides);
+    // TODO(tazjin): contains?
+    AttrDefs::iterator overrides = attrs.find(state.sOverrides);
     bool hasOverrides = overrides != attrs.end();
 
     /* The recursive attributes are evaluated in the new
@@ -855,17 +856,19 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
        been substituted into the bodies of the other attributes.
        Hence we need __overrides.) */
     if (hasOverrides) {
-      Value* vOverrides = (*v.attrs)[overrides->second.displ].value;
+      Value* vOverrides =
+          v.attrs->find(overrides->first)
+              ->value;  //(*v.attrs)[overrides->second.displ].value;
       state.forceAttrs(*vOverrides);
-      Bindings* newBnds =
-          state.allocBindings(v.attrs->capacity() + vOverrides->attrs->size());
-      for (auto& i : *v.attrs) {
+      Bindings* newBnds = state.allocBindings(/* capacity = */ 0);
+      for (auto& i : *v.attrs) {  // TODO(tazjin): copy constructor?
         newBnds->push_back(i);
       }
       for (auto& i : *vOverrides->attrs) {
         auto j = attrs.find(i.name);
         if (j != attrs.end()) {
-          (*newBnds)[j->second.displ] = i;
+          newBnds->push_back(i);
+          // (*newBnds)[j->second.displ] = i;
           env2.values[j->second.displ] = i.value;
         } else {
           newBnds->push_back(i);
@@ -875,6 +878,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
       v.attrs = newBnds;
     }
   } else {
+    // TODO(tazjin): insert range
     for (auto& i : attrs) {
       v.attrs->push_back(
           Attr(i.first, i.second.e->maybeThunk(state, env), &i.second.pos));