| author | |
| committer | |
| log | a4ce10df8087e7051340e14e4acd018092f935f0 |
| tree | 67a494c9ab0e80105aca3e3a222ff3adc0d48a91 |
| parent | 42cc4a406bd4d037f4203fa2ebca2853db33c780 |
| parent | 9d6f236728cf433b44048e21f81efdd167fe0098 |
| signature |
Using StringHashMap everywhere it's needed13 files changed, 33 insertions(+), 47 deletions(-)
doc/docgen.zig+2-2| ... | ... | @@ -307,7 +307,7 @@ const Node = union(enum) { |
| 307 | 307 | const Toc = struct { |
| 308 | 308 | nodes: []Node, |
| 309 | 309 | toc: []u8, |
| 310 | urls: std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8), | |
| 310 | urls: std.StringHashMap(Token), | |
| 311 | 311 | }; |
| 312 | 312 | |
| 313 | 313 | const Action = enum { |
| ... | ... | @@ -316,7 +316,7 @@ const Action = enum { |
| 316 | 316 | }; |
| 317 | 317 | |
| 318 | 318 | fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 319 | var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator); | |
| 319 | var urls = std.StringHashMap(Token).init(allocator); | |
| 320 | 320 | errdefer urls.deinit(); |
| 321 | 321 | |
| 322 | 322 | var header_stack_size: usize = 0; |
src-self-hosted/arg.zig+2-2| ... | ... | @@ -5,7 +5,7 @@ const mem = std.mem; |
| 5 | 5 | |
| 6 | 6 | const Allocator = mem.Allocator; |
| 7 | 7 | const ArrayList = std.ArrayList; |
| 8 | const HashMap = std.HashMap; | |
| 8 | const StringHashMap = std.StringHashMap; | |
| 9 | 9 | |
| 10 | 10 | fn trimStart(slice: []const u8, ch: u8) []const u8 { |
| 11 | 11 | var i: usize = 0; |
| ... | ... | @@ -73,7 +73,7 @@ fn readFlagArguments(allocator: *Allocator, args: []const []const u8, required: |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | const HashMapFlags = HashMap([]const u8, FlagArg, std.hash.Fnv1a_32.hash, mem.eql_slice_u8); | |
| 76 | const HashMapFlags = StringHashMap(FlagArg); | |
| 77 | 77 | |
| 78 | 78 | // A store for querying found flags and positional arguments. |
| 79 | 79 | pub const Args = struct { |
src-self-hosted/compilation.zig+1-1| ... | ... | @@ -249,7 +249,7 @@ pub const Compilation = struct { |
| 249 | 249 | const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql); |
| 250 | 250 | const PtrTypeTable = std.HashMap(*const Type.Pointer.Key, *Type.Pointer, Type.Pointer.Key.hash, Type.Pointer.Key.eql); |
| 251 | 251 | const FnTypeTable = std.HashMap(*const Type.Fn.Key, *Type.Fn, Type.Fn.Key.hash, Type.Fn.Key.eql); |
| 252 | const TypeTable = std.HashMap([]const u8, *Type, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 252 | const TypeTable = std.StringHashMap(*Type); | |
| 253 | 253 | |
| 254 | 254 | const CompileErrList = std.ArrayList(*Msg); |
| 255 | 255 |
src-self-hosted/decl.zig+1-1| ... | ... | @@ -20,7 +20,7 @@ pub const Decl = struct { |
| 20 | 20 | // TODO when we destroy the decl, deref the tree scope |
| 21 | 21 | tree_scope: *Scope.AstTree, |
| 22 | 22 | |
| 23 | pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 23 | pub const Table = std.StringHashMap(*Decl); | |
| 24 | 24 | |
| 25 | 25 | pub fn cast(base: *Decl, comptime T: type) ?*T { |
| 26 | 26 | if (base.id != @field(Id, @typeName(T))) return null; |
src-self-hosted/main.zig+1-1| ... | ... | @@ -541,7 +541,7 @@ const Fmt = struct { |
| 541 | 541 | color: errmsg.Color, |
| 542 | 542 | loop: *event.Loop, |
| 543 | 543 | |
| 544 | const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 544 | const SeenMap = std.StringHashMap(void); | |
| 545 | 545 | }; |
| 546 | 546 | |
| 547 | 547 | fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void { |
src-self-hosted/package.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ pub const Package = struct { |
| 10 | 10 | /// relative to root_src_dir |
| 11 | 11 | table: Table, |
| 12 | 12 | |
| 13 | pub const Table = std.HashMap([]const u8, *Package, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 13 | pub const Table = std.StringHashMap(*Package); | |
| 14 | 14 | |
| 15 | 15 | /// makes internal copies of root_src_dir and root_src_path |
| 16 | 16 | /// allocator should be an arena allocator because Package never frees anything |
src-self-hosted/stage1.zig+2-2| ... | ... | @@ -343,7 +343,7 @@ const Fmt = struct { |
| 343 | 343 | color: errmsg.Color, |
| 344 | 344 | allocator: *mem.Allocator, |
| 345 | 345 | |
| 346 | const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 346 | const SeenMap = std.StringHashMap(void); | |
| 347 | 347 | }; |
| 348 | 348 | |
| 349 | 349 | fn printErrMsgToFile( |
| ... | ... | @@ -376,7 +376,7 @@ fn printErrMsgToFile( |
| 376 | 376 | const text = text_buf.toOwnedSlice(); |
| 377 | 377 | |
| 378 | 378 | const stream = &file.outStream().stream; |
| 379 | try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text); | |
| 379 | try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text); | |
| 380 | 380 | |
| 381 | 381 | if (!color_on) return; |
| 382 | 382 |
std/buf_map.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std.zig"); |
| 2 | const HashMap = std.HashMap; | |
| 2 | const StringHashMap = std.StringHashMap; | |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | 5 | const testing = std.testing; |
| ... | ... | @@ -9,7 +9,7 @@ const testing = std.testing; |
| 9 | 9 | pub const BufMap = struct { |
| 10 | 10 | hash_map: BufMapHashMap, |
| 11 | 11 | |
| 12 | const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 12 | const BufMapHashMap = StringHashMap([]const u8); | |
| 13 | 13 | |
| 14 | 14 | pub fn init(allocator: *Allocator) BufMap { |
| 15 | 15 | var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) }; |
std/buf_set.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std.zig"); |
| 2 | const HashMap = @import("hash_map.zig").HashMap; | |
| 2 | const StringHashMap = std.StringHashMap; | |
| 3 | 3 | const mem = @import("mem.zig"); |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | 5 | const testing = std.testing; |
| ... | ... | @@ -7,7 +7,7 @@ const testing = std.testing; |
| 7 | 7 | pub const BufSet = struct { |
| 8 | 8 | hash_map: BufSetHashMap, |
| 9 | 9 | |
| 10 | const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 10 | const BufSetHashMap = StringHashMap(void); | |
| 11 | 11 | |
| 12 | 12 | pub fn init(a: *Allocator) BufSet { |
| 13 | 13 | var self = BufSet{ .hash_map = BufSetHashMap.init(a) }; |
std/build.zig+3-3| ... | ... | @@ -8,7 +8,7 @@ const panic = std.debug.panic; |
| 8 | 8 | const assert = debug.assert; |
| 9 | 9 | const warn = std.debug.warn; |
| 10 | 10 | const ArrayList = std.ArrayList; |
| 11 | const HashMap = std.HashMap; | |
| 11 | const StringHashMap = std.StringHashMap; | |
| 12 | 12 | const Allocator = mem.Allocator; |
| 13 | 13 | const process = std.process; |
| 14 | 14 | const BufSet = std.BufSet; |
| ... | ... | @@ -61,8 +61,8 @@ pub const Builder = struct { |
| 61 | 61 | C11, |
| 62 | 62 | }; |
| 63 | 63 | |
| 64 | const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 65 | const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 64 | const UserInputOptionsMap = StringHashMap(UserInputOption); | |
| 65 | const AvailableOptionsMap = StringHashMap(AvailableOption); | |
| 66 | 66 | |
| 67 | 67 | const AvailableOption = struct { |
| 68 | 68 | name: []const u8, |
std/hash_map.zig+1-3| ... | ... | @@ -23,9 +23,7 @@ pub fn StringHashMap(comptime V: type) type { |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | pub fn eqlString(a: []const u8, b: []const u8) bool { |
| 26 | if (a.len != b.len) return false; | |
| 27 | if (a.ptr == b.ptr) return true; | |
| 28 | return mem.compare(u8, a, b) == .Equal; | |
| 26 | return mem.eql(u8, a, b); | |
| 29 | 27 | } |
| 30 | 28 | |
| 31 | 29 | pub fn hashString(s: []const u8) u32 { |
std/json.zig+2-2| ... | ... | @@ -989,7 +989,7 @@ test "json.validate" { |
| 989 | 989 | const Allocator = std.mem.Allocator; |
| 990 | 990 | const ArenaAllocator = std.heap.ArenaAllocator; |
| 991 | 991 | const ArrayList = std.ArrayList; |
| 992 | const HashMap = std.HashMap; | |
| 992 | const StringHashMap = std.StringHashMap; | |
| 993 | 993 | |
| 994 | 994 | pub const ValueTree = struct { |
| 995 | 995 | arena: ArenaAllocator, |
| ... | ... | @@ -1000,7 +1000,7 @@ pub const ValueTree = struct { |
| 1000 | 1000 | } |
| 1001 | 1001 | }; |
| 1002 | 1002 | |
| 1003 | pub const ObjectMap = HashMap([]const u8, Value, mem.hash_slice_u8, mem.eql_slice_u8); | |
| 1003 | pub const ObjectMap = StringHashMap(Value); | |
| 1004 | 1004 | |
| 1005 | 1005 | pub const Value = union(enum) { |
| 1006 | 1006 | Null, |
std/mem.zig+13-25| ... | ... | @@ -339,6 +339,7 @@ test "mem.lessThan" { |
| 339 | 339 | /// Compares two slices and returns whether they are equal. |
| 340 | 340 | pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 341 | 341 | if (a.len != b.len) return false; |
| 342 | if (a.ptr == b.ptr) return true; | |
| 342 | 343 | for (a) |item, index| { |
| 343 | 344 | if (b[index] != item) return false; |
| 344 | 345 | } |
| ... | ... | @@ -738,47 +739,34 @@ test "writeIntBig and writeIntLittle" { |
| 738 | 739 | var buf9: [9]u8 = undefined; |
| 739 | 740 | |
| 740 | 741 | writeIntBig(u0, &buf0, 0x0); |
| 741 | testing.expect(eql_slice_u8(buf0[0..], [_]u8{})); | |
| 742 | testing.expect(eql(u8, buf0[0..], [_]u8{})); | |
| 742 | 743 | writeIntLittle(u0, &buf0, 0x0); |
| 743 | testing.expect(eql_slice_u8(buf0[0..], [_]u8{})); | |
| 744 | testing.expect(eql(u8, buf0[0..], [_]u8{})); | |
| 744 | 745 | |
| 745 | 746 | writeIntBig(u8, &buf1, 0x12); |
| 746 | testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x12})); | |
| 747 | testing.expect(eql(u8, buf1[0..], [_]u8{0x12})); | |
| 747 | 748 | writeIntLittle(u8, &buf1, 0x34); |
| 748 | testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x34})); | |
| 749 | testing.expect(eql(u8, buf1[0..], [_]u8{0x34})); | |
| 749 | 750 | |
| 750 | 751 | writeIntBig(u16, &buf2, 0x1234); |
| 751 | testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x12, 0x34 })); | |
| 752 | testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 })); | |
| 752 | 753 | writeIntLittle(u16, &buf2, 0x5678); |
| 753 | testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x78, 0x56 })); | |
| 754 | testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 })); | |
| 754 | 755 | |
| 755 | 756 | writeIntBig(u72, &buf9, 0x123456789abcdef024); |
| 756 | testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | |
| 757 | testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | |
| 757 | 758 | writeIntLittle(u72, &buf9, 0xfedcba9876543210ec); |
| 758 | testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | |
| 759 | testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | |
| 759 | 760 | |
| 760 | 761 | writeIntBig(i8, &buf1, -1); |
| 761 | testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xff})); | |
| 762 | testing.expect(eql(u8, buf1[0..], [_]u8{0xff})); | |
| 762 | 763 | writeIntLittle(i8, &buf1, -2); |
| 763 | testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xfe})); | |
| 764 | testing.expect(eql(u8, buf1[0..], [_]u8{0xfe})); | |
| 764 | 765 | |
| 765 | 766 | writeIntBig(i16, &buf2, -3); |
| 766 | testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xff, 0xfd })); | |
| 767 | testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd })); | |
| 767 | 768 | writeIntLittle(i16, &buf2, -4); |
| 768 | testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xfc, 0xff })); | |
| 769 | } | |
| 770 | ||
| 771 | pub fn hash_slice_u8(k: []const u8) u32 { | |
| 772 | // FNV 32-bit hash | |
| 773 | var h: u32 = 2166136261; | |
| 774 | for (k) |b| { | |
| 775 | h = (h ^ b) *% 16777619; | |
| 776 | } | |
| 777 | return h; | |
| 778 | } | |
| 779 | ||
| 780 | pub fn eql_slice_u8(a: []const u8, b: []const u8) bool { | |
| 781 | return eql(u8, a, b); | |
| 769 | testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff })); | |
| 782 | 770 | } |
| 783 | 771 | |
| 784 | 772 | /// Returns an iterator that iterates over the slices of `buffer` that are not |