Commit f08c6e4fe6
Changed files (12)
doc/docgen.zig
@@ -307,7 +307,7 @@ const Node = union(enum) {
const Toc = struct {
nodes: []Node,
toc: []u8,
- urls: std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8),
+ urls: std.StringHashMap(Token),
};
const Action = enum {
@@ -316,7 +316,7 @@ const Action = enum {
};
fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
- var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
+ var urls = std.StringHashMap(Token).init(allocator);
errdefer urls.deinit();
var header_stack_size: usize = 0;
src-self-hosted/arg.zig
@@ -5,7 +5,7 @@ const mem = std.mem;
const Allocator = mem.Allocator;
const ArrayList = std.ArrayList;
-const HashMap = std.HashMap;
+const StringHashMap = std.StringHashMap;
fn trimStart(slice: []const u8, ch: u8) []const u8 {
var i: usize = 0;
@@ -73,7 +73,7 @@ fn readFlagArguments(allocator: *Allocator, args: []const []const u8, required:
}
}
-const HashMapFlags = HashMap([]const u8, FlagArg, std.hash.Fnv1a_32.hash, mem.eql_slice_u8);
+const HashMapFlags = StringHashMap(FlagArg);
// A store for querying found flags and positional arguments.
pub const Args = struct {
src-self-hosted/compilation.zig
@@ -249,7 +249,7 @@ pub const Compilation = struct {
const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql);
const PtrTypeTable = std.HashMap(*const Type.Pointer.Key, *Type.Pointer, Type.Pointer.Key.hash, Type.Pointer.Key.eql);
const FnTypeTable = std.HashMap(*const Type.Fn.Key, *Type.Fn, Type.Fn.Key.hash, Type.Fn.Key.eql);
- const TypeTable = std.HashMap([]const u8, *Type, mem.hash_slice_u8, mem.eql_slice_u8);
+ const TypeTable = std.StringHashMap(*Type);
const CompileErrList = std.ArrayList(*Msg);
src-self-hosted/decl.zig
@@ -20,7 +20,7 @@ pub const Decl = struct {
// TODO when we destroy the decl, deref the tree scope
tree_scope: *Scope.AstTree,
- pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8);
+ pub const Table = std.StringHashMap(*Decl);
pub fn cast(base: *Decl, comptime T: type) ?*T {
if (base.id != @field(Id, @typeName(T))) return null;
src-self-hosted/main.zig
@@ -541,7 +541,7 @@ const Fmt = struct {
color: errmsg.Color,
loop: *event.Loop,
- const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
+ const SeenMap = std.StringHashMap(void);
};
fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
src-self-hosted/package.zig
@@ -10,7 +10,7 @@ pub const Package = struct {
/// relative to root_src_dir
table: Table,
- pub const Table = std.HashMap([]const u8, *Package, mem.hash_slice_u8, mem.eql_slice_u8);
+ pub const Table = std.StringHashMap(*Package);
/// makes internal copies of root_src_dir and root_src_path
/// allocator should be an arena allocator because Package never frees anything
src-self-hosted/stage1.zig
@@ -343,7 +343,7 @@ const Fmt = struct {
color: errmsg.Color,
allocator: *mem.Allocator,
- const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
+ const SeenMap = std.StringHashMap(void);
};
fn printErrMsgToFile(
@@ -376,7 +376,7 @@ fn printErrMsgToFile(
const text = text_buf.toOwnedSlice();
const stream = &file.outStream().stream;
- try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
+ try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
if (!color_on) return;
std/buf_map.zig
@@ -1,5 +1,5 @@
const std = @import("std.zig");
-const HashMap = std.HashMap;
+const StringHashMap = std.StringHashMap;
const mem = std.mem;
const Allocator = mem.Allocator;
const testing = std.testing;
@@ -9,7 +9,7 @@ const testing = std.testing;
pub const BufMap = struct {
hash_map: BufMapHashMap,
- const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);
+ const BufMapHashMap = StringHashMap([]const u8);
pub fn init(allocator: *Allocator) BufMap {
var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
std/buf_set.zig
@@ -1,5 +1,5 @@
const std = @import("std.zig");
-const HashMap = @import("hash_map.zig").HashMap;
+const StringHashMap = std.StringHashMap;
const mem = @import("mem.zig");
const Allocator = mem.Allocator;
const testing = std.testing;
@@ -7,7 +7,7 @@ const testing = std.testing;
pub const BufSet = struct {
hash_map: BufSetHashMap,
- const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
+ const BufSetHashMap = StringHashMap(void);
pub fn init(a: *Allocator) BufSet {
var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
std/build.zig
@@ -7,7 +7,7 @@ const debug = std.debug;
const assert = debug.assert;
const warn = std.debug.warn;
const ArrayList = std.ArrayList;
-const HashMap = std.HashMap;
+const StringHashMap = std.StringHashMap;
const Allocator = mem.Allocator;
const process = std.process;
const BufSet = std.BufSet;
@@ -60,8 +60,8 @@ pub const Builder = struct {
C11,
};
- const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);
- const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);
+ const UserInputOptionsMap = StringHashMap(UserInputOption);
+ const AvailableOptionsMap = StringHashMap(AvailableOption);
const AvailableOption = struct {
name: []const u8,
std/json.zig
@@ -989,7 +989,7 @@ test "json.validate" {
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
const ArrayList = std.ArrayList;
-const HashMap = std.HashMap;
+const StringHashMap = std.StringHashMap;
pub const ValueTree = struct {
arena: ArenaAllocator,
@@ -1000,7 +1000,7 @@ pub const ValueTree = struct {
}
};
-pub const ObjectMap = HashMap([]const u8, Value, mem.hash_slice_u8, mem.eql_slice_u8);
+pub const ObjectMap = StringHashMap(Value);
pub const Value = union(enum) {
Null,
std/mem.zig
@@ -738,47 +738,34 @@ test "writeIntBig and writeIntLittle" {
var buf9: [9]u8 = undefined;
writeIntBig(u0, &buf0, 0x0);
- testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
+ testing.expect(eql(u8, buf0[0..], [_]u8{}));
writeIntLittle(u0, &buf0, 0x0);
- testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
+ testing.expect(eql(u8, buf0[0..], [_]u8{}));
writeIntBig(u8, &buf1, 0x12);
- testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x12}));
+ testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));
writeIntLittle(u8, &buf1, 0x34);
- testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x34}));
+ testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));
writeIntBig(u16, &buf2, 0x1234);
- testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x12, 0x34 }));
+ testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));
writeIntLittle(u16, &buf2, 0x5678);
- testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x78, 0x56 }));
+ testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));
writeIntBig(u72, &buf9, 0x123456789abcdef024);
- testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
+ testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
- testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
+ testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
writeIntBig(i8, &buf1, -1);
- testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xff}));
+ testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));
writeIntLittle(i8, &buf1, -2);
- testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xfe}));
+ testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));
writeIntBig(i16, &buf2, -3);
- testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xff, 0xfd }));
+ testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));
writeIntLittle(i16, &buf2, -4);
- testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xfc, 0xff }));
-}
-
-pub fn hash_slice_u8(k: []const u8) u32 {
- // FNV 32-bit hash
- var h: u32 = 2166136261;
- for (k) |b| {
- h = (h ^ b) *% 16777619;
- }
- return h;
-}
-
-pub fn eql_slice_u8(a: []const u8, b: []const u8) bool {
- return eql(u8, a, b);
+ testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));
}
/// Returns an iterator that iterates over the slices of `buffer` that are not