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 › Build › Configuration › Wip › addDeduped Public Function addDeduped Doc Source Public Function std.Build.Configuration.Wip.addDeduped
pub fn addDeduped (wip : *Wip , comptime T : type , v : T ) Allocator .Error !T .Index Params File Build/Configuration.zig: 395
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417 pub fn addDeduped (wip : *Wip , comptime T : type , v : T ) Allocator .Error !T .Index {
const gpa = wip .gpa ;
const revert_index = wip .extra .items .len ;
const upper_bound_len = Storage .extraLen (v );
try wip .extra .ensureUnusedCapacity (gpa , upper_bound_len );
try wip .dedupe_table .ensureUnusedCapacityContext (gpa , 1 , @as (ExtraSlice .Context , .{
.extra = wip .extra .items ,
}));
const new_index = addExtraReservedErased (wip , T , v );
const len : u32 = @intCast (wip .extra .items .len - new_index );
assert (len != 0 );
const gop = wip .dedupe_table .getOrPutAssumeCapacityContext (.{
.index = new_index ,
.len = len ,
}, @as (ExtraSlice .Context , .{ .extra = wip .extra .items }));
if (gop .found_existing ) {
wip .extra .items .len = revert_index ;
return @fromBackingInt (@intCast (gop .key_ptr .index ));
}
return @fromBackingInt (@intCast (new_index ));
}
Same as
addExtrabut uses a hash map to possibly return an already existing index instead of appending toextra.