feature. See also
. The project being documented here (as the example) is the Zig library itself.
Builder.structConstAssumeCapacity
fn structConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant
File
Code
fn structConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
const type_item = self.type_items.items[@backingInt(ty)];
var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {
.structure, .packed_structure => type_item.data,
.named_structure => data: {
const body_ty = self.typeExtraData(Type.NamedStructure, type_item.data).body;
const body_item = self.type_items.items[@backingInt(body_ty)];
switch (body_item.tag) {
.structure, .packed_structure => break :data body_item.data,
else => unreachable,
}
},
else => unreachable,
});
const fields = extra.trail.next(extra.data.fields_len, Type, self);
for (fields, vals) |field, val| assert(field == val.typeOf(self));
for (vals) |val| {
if (!val.isZeroInit(self)) break;
} else return self.zeroInitConstAssumeCapacity(ty);
const tag: Constant.Tag = switch (ty.unnamedTag(self)) {
.structure => .structure,
.packed_structure => .packed_structure,
else => unreachable,
};
const result = self.getOrPutConstantAggregateAssumeCapacity(tag, ty, vals);
return result.constant;
}