feature. See also
. The project being documented here (as the example) is the Zig library itself.
Builder.vectorTypeAssumeCapacity
fn vectorTypeAssumeCapacity(
self: *Builder,
comptime kind: Type.Vector.Kind,
len: u32,
child: Type,
) Type
File
Code
fn vectorTypeAssumeCapacity(
self: *Builder,
comptime kind: Type.Vector.Kind,
len: u32,
child: Type,
) Type {
assert(child.isFloatingPoint() or child.isInteger(self) or child.isPointer(self));
const tag: Type.Tag = switch (kind) {
.normal => .vector,
.scalable => .scalable_vector,
};
const Adapter = struct {
builder: *const Builder,
pub fn hash(_: @This(), key: Type.Vector) u32 {
return @truncate(std.hash.Wyhash.hash(
comptime std.hash.int(@backingInt(tag)),
std.mem.asBytes(&key),
));
}
pub fn eql(ctx: @This(), lhs_key: Type.Vector, _: void, rhs_index: usize) bool {
const rhs_data = ctx.builder.type_items.items[rhs_index];
return rhs_data.tag == tag and
std.meta.eql(lhs_key, ctx.builder.typeExtraData(Type.Vector, rhs_data.data));
}
};
const data = Type.Vector{ .len = len, .child = child };
const gop = self.type_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
if (!gop.found_existing) {
gop.key_ptr.* = {};
gop.value_ptr.* = {};
self.type_items.appendAssumeCapacity(.{
.tag = tag,
.data = self.addTypeExtraAssumeCapacity(data),
});
}
return @fromBackingInt(@intCast(gop.index));
}