From fc9430f56798a53f9393a697f4ccd6bf9981b970 Mon Sep 17 00:00:00 2001 From: Martin Wickham Date: Thu, 3 Jun 2021 15:39:26 -0500 Subject: Breaking hash map changes for 0.8.0 - hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig --- src/AstGen.zig | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/AstGen.zig') diff --git a/src/AstGen.zig b/src/AstGen.zig index 790984dc8f..564813f9e3 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -144,9 +144,7 @@ pub fn generate(gpa: *Allocator, tree: ast.Tree) InnerError!Zir { astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{ .imports_len = @intCast(u32, astgen.imports.count()), }); - for (astgen.imports.items()) |entry| { - astgen.extra.appendAssumeCapacity(entry.key); - } + astgen.extra.appendSliceAssumeCapacity(astgen.imports.keys()); } return Zir{ @@ -7932,13 +7930,13 @@ fn identAsString(astgen: *AstGen, ident_token: ast.TokenIndex) !u32 { const gop = try astgen.string_table.getOrPut(gpa, key); if (gop.found_existing) { string_bytes.shrinkRetainingCapacity(str_index); - return gop.entry.value; + return gop.value_ptr.*; } else { // We have to dupe the key into the arena, otherwise the memory // becomes invalidated when string_bytes gets data appended. // TODO https://github.com/ziglang/zig/issues/8528 - gop.entry.key = try astgen.arena.dupe(u8, key); - gop.entry.value = str_index; + gop.key_ptr.* = try astgen.arena.dupe(u8, key); + gop.value_ptr.* = str_index; try string_bytes.append(gpa, 0); return str_index; } @@ -7957,15 +7955,15 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: ast.TokenIndex) !IndexSlice { if (gop.found_existing) { string_bytes.shrinkRetainingCapacity(str_index); return IndexSlice{ - .index = gop.entry.value, + .index = gop.value_ptr.*, .len = @intCast(u32, key.len), }; } else { // We have to dupe the key into the arena, otherwise the memory // becomes invalidated when string_bytes gets data appended. // TODO https://github.com/ziglang/zig/issues/8528 - gop.entry.key = try astgen.arena.dupe(u8, key); - gop.entry.value = str_index; + gop.key_ptr.* = try astgen.arena.dupe(u8, key); + gop.value_ptr.* = str_index; // Still need a null byte because we are using the same table // to lookup null terminated strings, so if we get a match, it has to // be null terminated for that to work. @@ -9122,10 +9120,10 @@ fn declareNewName( return astgen.failNodeNotes(node, "redeclaration of '{s}'", .{ name, }, &[_]u32{ - try astgen.errNoteNode(gop.entry.value, "other declaration here", .{}), + try astgen.errNoteNode(gop.value_ptr.*, "other declaration here", .{}), }); } - gop.entry.value = node; + gop.value_ptr.* = node; break; }, .top => break, -- cgit v1.2.3