Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › zig › llvm › Builder › metadataSimpleAssumeCapacity Private Function metadataSimpleAssumeCapacity Doc Source Private Function std.zig.llvm.Builder.metadataSimpleAssumeCapacity
fn metadataSimpleAssumeCapacity (self : *Builder , tag : Metadata .Tag , value : anytype ) Metadata Params File zig/llvm/Builder.zig: 13772
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809 fn metadataSimpleAssumeCapacity (self : *Builder , tag : Metadata .Tag , value : anytype ) Metadata {
const Key = struct {
tag : Metadata .Tag ,
value : @TypeOf (value ),
};
const Adapter = struct {
builder : *const Builder ,
pub fn hash (_ : @This (), key : Key ) u32 {
var hasher = std .hash .Wyhash .init (std .hash .int (@backingInt (key .tag )));
inline for (@typeInfo (@TypeOf (value )).@"struct" .field_names ) |field_name | {
hasher .update (std .mem .asBytes (&@field (key .value , field_name )));
}
return @truncate (hasher .final ());
}
pub fn eql (ctx : @This (), lhs_key : Key , _ : void , rhs_index : usize ) bool {
if (lhs_key .tag != ctx .builder .metadata_items .items (.tag )[rhs_index ]) return false ;
const rhs_data = ctx .builder .metadata_items .items (.data )[rhs_index ];
const rhs_extra = ctx .builder .metadataExtraData (@TypeOf (value ), rhs_data );
return std .meta .eql (lhs_key .value , rhs_extra );
}
};
const gop = self .metadata_map .getOrPutAssumeCapacityAdapted (
Key { .tag = tag , .value = value },
Adapter { .builder = self },
);
if (!gop .found_existing ) {
gop .key_ptr .* = {};
gop .value_ptr .* = {};
self .metadata_items .appendAssumeCapacity (.{
.tag = tag ,
.data = self .addMetadataExtraAssumeCapacity (value ),
});
}
return .{ .index = @intCast (gop .index ), .kind = .node };
}