diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh index c42aba0f6..3bf23eeb2 100644 --- a/src/libexpr/attr-set.hh +++ b/src/libexpr/attr-set.hh @@ -15,11 +15,15 @@ struct Value; /* Map one attribute name to its value. */ struct Attr { + /* the placement of `name` and `pos` in this struct is important. + both of them are uint32 wrappers, they are next to each other + to make sure that Attr has no padding on 64 bit machines. that + way we keep Attr size at two words with no wasted space. */ SymbolIdx name; - Value * value; PosIdx pos; + Value * value; Attr(SymbolIdx name, Value * value, PosIdx pos = noPos) - : name(name), value(value), pos(pos) { }; + : name(name), pos(pos), value(value) { }; Attr() { }; bool operator < (const Attr & a) const { @@ -27,6 +31,11 @@ struct Attr } }; +static_assert(sizeof(Attr) == 2 * sizeof(uint32_t) + sizeof(Value *), + "performance of the evaluator is highly sensitive to the size of Attr. " + "avoid introducing any padding into Attr if at all possible, and do not " + "introduce new fields that need not be present for almost every instance."); + /* Bindings contains all the attributes of an attribute set. It is defined by its size and its capacity, the capacity being the number of Attr elements allocated after this structure, while the size corresponds to