diff options
| author | Ominitay <37453713+Ominitay@users.noreply.github.com> | 2021-10-27 15:53:29 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-27 16:07:48 -0400 |
| commit | c1a5ff34f3f68a2a0bc32828ab483328cd436fea (patch) | |
| tree | bad85387a89da38890f72696ccfc0ae3c416ab0f /lib/std/atomic/stack.zig | |
| parent | 9024f27d8f5cb651e2260348ce0ee6fd67fc2c32 (diff) | |
| download | zig-c1a5ff34f3f68a2a0bc32828ab483328cd436fea.tar.gz zig-c1a5ff34f3f68a2a0bc32828ab483328cd436fea.zip | |
std.rand: Refactor `Random` interface
These changes have been made to resolve issue #10037. The `Random`
interface was implemented in such a way that causes significant slowdown
when calling the `fill` function of the rng used.
The `Random` interface is no longer stored in a field of the rng, and is
instead returned by the child function `random()` of the rng. This
avoids the performance issues caused by the interface.
Diffstat (limited to 'lib/std/atomic/stack.zig')
| -rw-r--r-- | lib/std/atomic/stack.zig | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index 1005195b29..35f6914252 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -147,10 +147,11 @@ test "std.atomic.stack" { fn startPuts(ctx: *Context) u8 { var put_count: usize = puts_per_thread; - var r = std.rand.DefaultPrng.init(0xdeadbeef); + var prng = std.rand.DefaultPrng.init(0xdeadbeef); + const random = prng.random(); while (put_count != 0) : (put_count -= 1) { std.time.sleep(1); // let the os scheduler be our fuzz - const x = @bitCast(i32, r.random.int(u32)); + const x = @bitCast(i32, random.int(u32)); const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; node.* = Stack(i32).Node{ .next = undefined, |
