diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-03 16:13:28 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-03 16:13:28 -0500 |
| commit | dfbc063f79dc1358208216b466c1bf8c44baa430 (patch) | |
| tree | 219c5f46a2e688fc1799117a1680102528691ce3 /std/io.zig | |
| parent | c90c256868a80cd35e9ba679ba082330592620c9 (diff) | |
| download | zig-dfbc063f79dc1358208216b466c1bf8c44baa430.tar.gz zig-dfbc063f79dc1358208216b466c1bf8c44baa430.zip | |
`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
Diffstat (limited to 'std/io.zig')
| -rw-r--r-- | std/io.zig | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/std/io.zig b/std/io.zig index 46625cd34b..c8701aeda6 100644 --- a/std/io.zig +++ b/std/io.zig @@ -944,12 +944,13 @@ pub const BufferedAtomicFile = struct { pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { // TODO with well defined copy elision we don't need this allocation - var self = try allocator.create(BufferedAtomicFile{ + var self = try allocator.create(BufferedAtomicFile); + self.* = BufferedAtomicFile{ .atomic_file = undefined, .file_stream = undefined, .buffered_stream = undefined, .allocator = allocator, - }); + }; errdefer allocator.destroy(self); self.atomic_file = try os.AtomicFile.init(dest_path, os.File.default_mode); |
