authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-08 15:59:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-08 15:59:03-07:00
logf98cffc615bb7ea73eee3bd24ae8a957fe8ebb82
treef68e0ce1a1a7e62665be0db0fc701f79c25189aa
parent5b57e35ce0c83dc48587c19cf28db509bba2226b

std: general purpose allocator: use AutoHashMap

As pointed out by Sahnvour, AutoHashMap is both more convenient and will have better performance in this case.

1 files changed, 1 insertions(+), 12 deletions(-)

lib/std/heap/general_purpose_allocator.zig+1-12
...@@ -189,7 +189,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -189,7 +189,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
189 std.debug.dumpStackTrace(stack_trace);189 std.debug.dumpStackTrace(stack_trace);
190 }190 }
191 };191 };
192 const LargeAllocTable = std.HashMapUnmanaged(usize, LargeAlloc, hash_addr, eql_addr, false);192 const LargeAllocTable = std.AutoHashMapUnmanaged(usize, LargeAlloc);
193193
194 // Bucket: In memory, in order:194 // Bucket: In memory, in order:
195 // * BucketHeader195 // * BucketHeader
...@@ -609,17 +609,6 @@ const TraceKind = enum {...@@ -609,17 +609,6 @@ const TraceKind = enum {
609 free,609 free,
610};610};
611611
612fn hash_addr(addr: usize) u32 {
613 if (@sizeOf(usize) == @sizeOf(u32))
614 return addr;
615 comptime assert(@sizeOf(usize) == 8);
616 return @intCast(u32, addr >> 32) ^ @truncate(u32, addr);
617}
618
619fn eql_addr(a: usize, b: usize) bool {
620 return a == b;
621}
622
623const test_config = Config{};612const test_config = Config{};
624613
625test "small allocations - free in same order" {614test "small allocations - free in same order" {