fn identAsString(zg: *ZonGen, ident_token: Ast.TokenIndex) !Zoir.NullTerminatedString zg: *ZonGenident_token: Ast.TokenIndex600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618fn identAsString(zg: *ZonGen, ident_token: Ast.TokenIndex) !Zoir.NullTerminatedString {
const gpa = zg.gpa;
const string_bytes = &zg.string_bytes;
const str_index = try zg.appendIdentStr(ident_token);
const key: []const u8 = string_bytes.items[str_index..];
const gop = try zg.string_table.getOrPutContextAdapted(
gpa,
key,
StringIndexAdapter{ .bytes = string_bytes },
StringIndexContext{ .bytes = string_bytes },
);
if (gop.found_existing) {
string_bytes.shrinkRetainingCapacity(str_index);
return @fromBackingInt(@intCast(gop.key_ptr.*));
}
gop.key_ptr.* = str_index;
try string_bytes.append(gpa, 0);
return @fromBackingInt(@intCast(str_index));
}