refactor(3p/nix/libexpr): state->allocBindings -> Bindings::NewGC
EvalState::allocBindings had little to do with Bindings, other than returning them, and didn't belong in that class.
This commit is contained in:
parent
e24466c795
commit
b3c9166b23
10 changed files with 14 additions and 15 deletions
7
third_party/nix/src/libexpr/attr-set.cc
vendored
7
third_party/nix/src/libexpr/attr-set.cc
vendored
|
|
@ -49,10 +49,7 @@ void Bindings::merge(Bindings* other) {
|
|||
attributes_.swap(other->attributes_);
|
||||
}
|
||||
|
||||
// Allocate a new attribute set, making it visible to the garbage collector.
|
||||
Bindings* EvalState::allocBindings(size_t _capacity) {
|
||||
return new (GC) Bindings;
|
||||
}
|
||||
Bindings* Bindings::NewGC() { return new (GC) Bindings; }
|
||||
|
||||
void EvalState::mkAttrs(Value& v, size_t capacity) {
|
||||
if (capacity == 0) {
|
||||
|
|
@ -61,7 +58,7 @@ void EvalState::mkAttrs(Value& v, size_t capacity) {
|
|||
}
|
||||
clearValue(v);
|
||||
v.type = tAttrs;
|
||||
v.attrs = new (GC) Bindings;
|
||||
v.attrs = Bindings::NewGC();
|
||||
nrAttrsets++;
|
||||
nrAttrsInAttrsets += capacity;
|
||||
}
|
||||
|
|
|
|||
4
third_party/nix/src/libexpr/attr-set.hh
vendored
4
third_party/nix/src/libexpr/attr-set.hh
vendored
|
|
@ -33,6 +33,10 @@ class Bindings {
|
|||
public:
|
||||
typedef absl::btree_map<Symbol, Attr>::iterator iterator;
|
||||
|
||||
// Allocate a new attribute set that is visible to the garbage
|
||||
// collector.
|
||||
static Bindings* NewGC();
|
||||
|
||||
// Return the number of contained elements.
|
||||
size_t size();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ MixEvalArgs::MixEvalArgs() {
|
|||
}
|
||||
|
||||
Bindings* MixEvalArgs::getAutoArgs(EvalState& state) {
|
||||
Bindings* res = state.allocBindings(autoArgs.size());
|
||||
Bindings* res = Bindings::NewGC();
|
||||
for (auto& i : autoArgs) {
|
||||
Value* v = state.allocValue();
|
||||
if (i.second[0] == 'E') {
|
||||
|
|
|
|||
4
third_party/nix/src/libexpr/eval.cc
vendored
4
third_party/nix/src/libexpr/eval.cc
vendored
|
|
@ -372,7 +372,7 @@ EvalState::EvalState(const Strings& _searchPath, const ref<Store>& store)
|
|||
|
||||
clearValue(vEmptySet);
|
||||
vEmptySet.type = tAttrs;
|
||||
vEmptySet.attrs = allocBindings(0);
|
||||
vEmptySet.attrs = Bindings::NewGC();
|
||||
|
||||
createBaseEnv();
|
||||
}
|
||||
|
|
@ -857,7 +857,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
|
|||
if (hasOverrides) {
|
||||
Value* vOverrides = v.attrs->find(overrides->first)->second.value;
|
||||
state.forceAttrs(*vOverrides);
|
||||
Bindings* newBnds = state.allocBindings(/* capacity = */ 0);
|
||||
Bindings* newBnds = Bindings::NewGC();
|
||||
for (auto& i : *v.attrs) { // TODO(tazjin): copy constructor?
|
||||
newBnds->push_back(i.second);
|
||||
}
|
||||
|
|
|
|||
2
third_party/nix/src/libexpr/eval.hh
vendored
2
third_party/nix/src/libexpr/eval.hh
vendored
|
|
@ -258,8 +258,6 @@ class EvalState {
|
|||
|
||||
Value* allocAttr(Value& vAttrs, const Symbol& name);
|
||||
|
||||
[[deprecated]] static Bindings* allocBindings(size_t capacity);
|
||||
|
||||
void mkList(Value& v, size_t size);
|
||||
void mkAttrs(Value& v, size_t capacity);
|
||||
void mkThunk_(Value& v, Expr* expr);
|
||||
|
|
|
|||
2
third_party/nix/src/libexpr/get-drvs.cc
vendored
2
third_party/nix/src/libexpr/get-drvs.cc
vendored
|
|
@ -293,7 +293,7 @@ bool DrvInfo::queryMetaBool(const std::string& name, bool def) {
|
|||
void DrvInfo::setMeta(const std::string& name, Value* v) {
|
||||
getMeta();
|
||||
Bindings* old = meta;
|
||||
meta = state->allocBindings(1 + (old != nullptr ? old->size() : 0));
|
||||
meta = Bindings::NewGC();
|
||||
Symbol sym = state->symbols.Create(name);
|
||||
if (old != nullptr) {
|
||||
for (auto i : *old) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue