From dfbc063f79dc1358208216b466c1bf8c44baa430 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 3 Feb 2019 16:13:28 -0500 Subject: `std.mem.Allocator.create` replaced with better API `std.mem.Allocator.createOne` is renamed to `std.mem.Allocator.create`. The problem with the previous API is that even after copy elision, the initalization value passed as a parameter would always be a copy. With the new API, once copy elision is done, initialization functions can directly initialize allocated memory in place. Related: * #1872 * #1873 --- std/atomic/stack.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'std/atomic/stack.zig') diff --git a/std/atomic/stack.zig b/std/atomic/stack.zig index 1e4981353b..503fa0c0ce 100644 --- a/std/atomic/stack.zig +++ b/std/atomic/stack.zig @@ -155,10 +155,11 @@ fn startPuts(ctx: *Context) u8 { while (put_count != 0) : (put_count -= 1) { std.os.time.sleep(1); // let the os scheduler be our fuzz const x = @bitCast(i32, r.random.scalar(u32)); - const node = ctx.allocator.create(Stack(i32).Node{ + const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; + node.* = Stack(i32).Node{ .next = undefined, .data = x, - }) catch unreachable; + }; ctx.stack.push(node); _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); } -- cgit v1.2.3