mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
The short answer for why we need to do this is so we can consistently do `#include "nix/..."`. Without this change, there are ways to still make that work, but they are hacky, and they have downsides such as making it harder to make sure headers from the wrong Nix library (e..g. `libnixexpr` headers in `libnixutil`) aren't being used. The C API alraedy used `nix_api_*`, so its headers are *not* put in subdirectories accordingly. Progress on #7876 We resisted doing this for a while because it would be annoying to not have the header source file pairs close by / easy to change file path/name from one to the other. But I am ameliorating that with symlinks in the next commit.
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#include "nix/attr-set.hh"
|
|
#include "nix/eval-inline.hh"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
/* Allocate a new array of attributes for an attribute set with a specific
|
|
capacity. The space is implicitly reserved after the Bindings
|
|
structure. */
|
|
Bindings * EvalState::allocBindings(size_t capacity)
|
|
{
|
|
if (capacity == 0)
|
|
return &emptyBindings;
|
|
if (capacity > std::numeric_limits<Bindings::size_t>::max())
|
|
throw Error("attribute set of size %d is too big", capacity);
|
|
nrAttrsets++;
|
|
nrAttrsInAttrsets += capacity;
|
|
return new (allocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings((Bindings::size_t) capacity);
|
|
}
|
|
|
|
|
|
Value & BindingsBuilder::alloc(Symbol name, PosIdx pos)
|
|
{
|
|
auto value = state.allocValue();
|
|
bindings->push_back(Attr(name, value, pos));
|
|
return *value;
|
|
}
|
|
|
|
|
|
Value & BindingsBuilder::alloc(std::string_view name, PosIdx pos)
|
|
{
|
|
return alloc(state.symbols.create(name), pos);
|
|
}
|
|
|
|
|
|
void Bindings::sort()
|
|
{
|
|
if (size_) std::sort(begin(), end());
|
|
}
|
|
|
|
|
|
Value & Value::mkAttrs(BindingsBuilder & bindings)
|
|
{
|
|
mkAttrs(bindings.finish());
|
|
return *this;
|
|
}
|
|
|
|
|
|
}
|