1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 03:21:16 +02:00

C API: refactor ListBuilder

This commit is contained in:
José Luis Lafuente 2024-02-27 22:08:00 +01:00 committed by José Luis Lafuente
parent 34d15e8f2f
commit 1a574c6c60
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
4 changed files with 50 additions and 37 deletions

View file

@ -3,6 +3,33 @@
#include "eval.hh"
#include "attr-set.hh"
#include "nix_api_value.h"
class CListBuilder
{
private:
std::vector<nix::Value *> values;
public:
CListBuilder(size_t capacity)
{
values.reserve(capacity);
}
void push_back(nix::Value * value)
{
values.push_back(value);
}
Value * finish(nix::EvalState * state, nix::Value * list)
{
state->mkList(*list, values.size());
for (size_t n = 0; n < list->listSize(); ++n) {
list->listElems()[n] = values[n];
}
return list;
}
};
struct EvalState
{
@ -14,6 +41,11 @@ struct BindingsBuilder
nix::BindingsBuilder builder;
};
struct ListBuilder
{
CListBuilder builder;
};
struct nix_string_return
{
std::string str;