authorgravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-06-21 00:39:19+09:00
committergravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-06-21 00:39:19+09:00
log457c0f0a7e424177e7d8d00f4429da292b7c67d5
tree0780bc6e86e8994f60c3dc4098c96baea151fe3a
parent55193cb13bbc69350474f6a66728319b41149274

std.mem: remove allocator create in favor of construct; ref #733


1 files changed, 8 insertions(+), 9 deletions(-)

std/mem.zig+8-9
...@@ -32,15 +32,7 @@ pub const Allocator = struct {...@@ -32,15 +32,7 @@ pub const Allocator = struct {
32 freeFn: fn (self: *Allocator, old_mem: []u8) void,32 freeFn: fn (self: *Allocator, old_mem: []u8) void,
3333
34 /// Call destroy with the result34 /// Call destroy with the result
35 pub fn create(self: *Allocator, comptime T: type) !*T {35 pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) {
36 if (@sizeOf(T) == 0) return *{};
37 const slice = try self.alloc(T, 1);
38 return &slice[0];
39 }
40
41 /// Call destroy with the result
42 /// TODO once #733 is solved, this will replace create
43 pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
44 const T = @typeOf(init);36 const T = @typeOf(init);
45 if (@sizeOf(T) == 0) return &{};37 if (@sizeOf(T) == 0) return &{};
46 const slice = try self.alloc(T, 1);38 const slice = try self.alloc(T, 1);
...@@ -49,6 +41,13 @@ pub const Allocator = struct {...@@ -49,6 +41,13 @@ pub const Allocator = struct {
49 return ptr;41 return ptr;
50 }42 }
5143
44 /// Alias of create
45 /// Call destroy with the result
46 pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
47 debug.warn("std.mem.Allocator.construct is deprecated;\n");
48 return self.create(init);
49 }
50
52 /// `ptr` should be the return value of `construct` or `create`51 /// `ptr` should be the return value of `construct` or `create`
53 pub fn destroy(self: *Allocator, ptr: var) void {52 pub fn destroy(self: *Allocator, ptr: var) void {
54 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));53 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));