refactor(3p/tvix): convert NixList usage to shared_ptr
Starting to reclaim memory. Fairly simple mechanical replacement. Change-Id: I6b4c5c5596729470d1a049eba61e69e8097decf4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1971 Tested-by: BuildkiteCI Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
parent
381ce8a666
commit
2c19bd6662
4 changed files with 12 additions and 12 deletions
12
third_party/nix/src/libexpr/eval.cc
vendored
12
third_party/nix/src/libexpr/eval.cc
vendored
|
@ -598,15 +598,15 @@ Env& EvalState::allocEnv(size_t size) {
|
|||
return *env;
|
||||
}
|
||||
|
||||
void EvalState::mkList(Value& v, NixList* list) {
|
||||
void EvalState::mkList(Value& v, std::shared_ptr<NixList> list) {
|
||||
nrListElems += list->size();
|
||||
clearValue(v);
|
||||
v.type = tList;
|
||||
v.list = list;
|
||||
nrListElems += list->size();
|
||||
}
|
||||
|
||||
void EvalState::mkList(Value& v, size_t size) {
|
||||
EvalState::mkList(v, new NixList(size));
|
||||
EvalState::mkList(v, std::make_shared<NixList>(size));
|
||||
}
|
||||
|
||||
unsigned long nrThunks = 0;
|
||||
|
@ -1224,7 +1224,7 @@ void ExprOpConcatLists::eval(EvalState& state, Env& env, Value& v) {
|
|||
void EvalState::concatLists(Value& v, const NixList& lists, const Pos& pos) {
|
||||
nrListConcats++;
|
||||
|
||||
auto outlist = new NixList();
|
||||
auto outlist = std::make_shared<NixList>();
|
||||
|
||||
for (Value* list : lists) {
|
||||
forceList(*list, pos);
|
||||
|
@ -1816,8 +1816,8 @@ size_t valueSize(const Value& v) {
|
|||
}
|
||||
break;
|
||||
case tList:
|
||||
if (seenLists.find(v.list) == seenLists.end()) {
|
||||
seenLists.insert(v.list);
|
||||
if (seenLists.find(v.list.get()) == seenLists.end()) {
|
||||
seenLists.insert(v.list.get());
|
||||
sz += v.listSize() * sizeof(Value*);
|
||||
for (const Value* v : *v.list) {
|
||||
sz += doValue(*v);
|
||||
|
|
2
third_party/nix/src/libexpr/eval.hh
vendored
2
third_party/nix/src/libexpr/eval.hh
vendored
|
@ -258,7 +258,7 @@ class EvalState {
|
|||
Value* allocAttr(Value& vAttrs, const Symbol& name);
|
||||
|
||||
// Create a list value from the specified vector.
|
||||
void mkList(Value& v, NixList* list);
|
||||
void mkList(Value& v, std::shared_ptr<NixList> list);
|
||||
|
||||
// Create a list value, allocating as many elements as specified in
|
||||
// size. This is used for the many cases in this codebase where
|
||||
|
|
8
third_party/nix/src/libexpr/primops.cc
vendored
8
third_party/nix/src/libexpr/primops.cc
vendored
|
@ -1603,7 +1603,7 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args,
|
|||
|
||||
// Copy of the input list which can be sorted in place.
|
||||
v.type = tList;
|
||||
v.list = new NixList(*args[1]->list);
|
||||
v.list = std::make_shared<NixList>(*args[1]->list);
|
||||
|
||||
std::for_each(v.list->begin(), v.list->end(),
|
||||
[&](Value* val) { state.forceValue(*val); });
|
||||
|
@ -1633,8 +1633,8 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args,
|
|||
state.forceFunction(*args[0], pos);
|
||||
state.forceList(*args[1], pos);
|
||||
|
||||
NixList* right = new NixList();
|
||||
NixList* wrong = new NixList();
|
||||
std::shared_ptr<NixList> right = std::make_shared<NixList>();
|
||||
std::shared_ptr<NixList> wrong = std::make_shared<NixList>();
|
||||
|
||||
for (Value* elem : *args[1]->list) {
|
||||
state.forceValue(*elem, pos);
|
||||
|
@ -1664,7 +1664,7 @@ static void prim_concatMap(EvalState& state, const Pos& pos, Value** args,
|
|||
state.forceFunction(*args[0], pos);
|
||||
state.forceList(*args[1], pos);
|
||||
|
||||
NixList* outlist = new NixList;
|
||||
std::shared_ptr<NixList> outlist = std::make_shared<NixList>();
|
||||
|
||||
for (Value* elem : *args[1]->list) {
|
||||
auto out = state.allocValue();
|
||||
|
|
2
third_party/nix/src/libexpr/value.hh
vendored
2
third_party/nix/src/libexpr/value.hh
vendored
|
@ -96,7 +96,7 @@ struct Value {
|
|||
NixString string;
|
||||
const char* path;
|
||||
std::shared_ptr<Bindings> attrs;
|
||||
NixList* list;
|
||||
std::shared_ptr<NixList> list;
|
||||
NixThunk thunk;
|
||||
NixApp app; // TODO(tazjin): "app"?
|
||||
NixLambda lambda;
|
||||
|
|
Loading…
Reference in a new issue