diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-11-30 18:48:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-30 18:48:31 -0800 |
| commit | 7355a201336c8e3892427e5932fe5cdd46cf96df (patch) | |
| tree | 4ccec922634586847d02f2324d0db75f25200188 /src/link/tapi | |
| parent | dd62a6d2e8de522187fd096354e7156cca1821c5 (diff) | |
| parent | 066eaa5e9cbfde172449f6d95bb884c7d86ac10c (diff) | |
| download | zig-7355a201336c8e3892427e5932fe5cdd46cf96df.tar.gz zig-7355a201336c8e3892427e5932fe5cdd46cf96df.zip | |
Merge pull request #10055 from leecannon/allocator_refactor
Allocgate
Diffstat (limited to 'src/link/tapi')
| -rw-r--r-- | src/link/tapi/parse.zig | 14 | ||||
| -rw-r--r-- | src/link/tapi/yaml.zig | 17 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/link/tapi/parse.zig b/src/link/tapi/parse.zig index 0c923f961b..0c40f613dc 100644 --- a/src/link/tapi/parse.zig +++ b/src/link/tapi/parse.zig @@ -37,7 +37,7 @@ pub const Node = struct { return @fieldParentPtr(T, "base", self); } - pub fn deinit(self: *Node, allocator: *Allocator) void { + pub fn deinit(self: *Node, allocator: Allocator) void { switch (self.tag) { .doc => @fieldParentPtr(Node.Doc, "base", self).deinit(allocator), .map => @fieldParentPtr(Node.Map, "base", self).deinit(allocator), @@ -69,7 +69,7 @@ pub const Node = struct { pub const base_tag: Node.Tag = .doc; - pub fn deinit(self: *Doc, allocator: *Allocator) void { + pub fn deinit(self: *Doc, allocator: Allocator) void { if (self.value) |node| { node.deinit(allocator); allocator.destroy(node); @@ -113,7 +113,7 @@ pub const Node = struct { value: *Node, }; - pub fn deinit(self: *Map, allocator: *Allocator) void { + pub fn deinit(self: *Map, allocator: Allocator) void { for (self.values.items) |entry| { entry.value.deinit(allocator); allocator.destroy(entry.value); @@ -149,7 +149,7 @@ pub const Node = struct { pub const base_tag: Node.Tag = .list; - pub fn deinit(self: *List, allocator: *Allocator) void { + pub fn deinit(self: *List, allocator: Allocator) void { for (self.values.items) |node| { node.deinit(allocator); allocator.destroy(node); @@ -198,12 +198,12 @@ pub const Node = struct { }; pub const Tree = struct { - allocator: *Allocator, + allocator: Allocator, source: []const u8, tokens: []Token, docs: std.ArrayListUnmanaged(*Node) = .{}, - pub fn init(allocator: *Allocator) Tree { + pub fn init(allocator: Allocator) Tree { return .{ .allocator = allocator, .source = undefined, @@ -266,7 +266,7 @@ pub const Tree = struct { }; const Parser = struct { - allocator: *Allocator, + allocator: Allocator, tree: *Tree, token_it: *TokenIterator, scopes: std.ArrayListUnmanaged(Scope) = .{}, diff --git a/src/link/tapi/yaml.zig b/src/link/tapi/yaml.zig index 25d2c73e82..7c1997604d 100644 --- a/src/link/tapi/yaml.zig +++ b/src/link/tapi/yaml.zig @@ -149,7 +149,7 @@ pub const Value = union(ValueType) { }; } - fn fromNode(arena: *Allocator, tree: *const Tree, node: *const Node, type_hint: ?ValueType) YamlError!Value { + fn fromNode(arena: Allocator, tree: *const Tree, node: *const Node, type_hint: ?ValueType) YamlError!Value { if (node.cast(Node.Doc)) |doc| { const inner = doc.value orelse { // empty doc @@ -246,17 +246,18 @@ pub const Yaml = struct { } } - pub fn load(allocator: *Allocator, source: []const u8) !Yaml { + pub fn load(allocator: Allocator, source: []const u8) !Yaml { var arena = ArenaAllocator.init(allocator); + const arena_allocator = arena.allocator(); - var tree = Tree.init(&arena.allocator); + var tree = Tree.init(arena_allocator); try tree.parse(source); - var docs = std.ArrayList(Value).init(&arena.allocator); + var docs = std.ArrayList(Value).init(arena_allocator); try docs.ensureUnusedCapacity(tree.docs.items.len); for (tree.docs.items) |node| { - const value = try Value.fromNode(&arena.allocator, &tree, node, null); + const value = try Value.fromNode(arena_allocator, &tree, node, null); docs.appendAssumeCapacity(value); } @@ -299,7 +300,7 @@ pub const Yaml = struct { .Pointer => |info| { switch (info.size) { .Slice => { - var parsed = try self.arena.allocator.alloc(info.child, self.docs.items.len); + var parsed = try self.arena.allocator().alloc(info.child, self.docs.items.len); for (self.docs.items) |doc, i| { parsed[i] = try self.parseValue(info.child, doc); } @@ -361,7 +362,7 @@ pub const Yaml = struct { inline for (struct_info.fields) |field| { const value: ?Value = map.get(field.name) orelse blk: { - const field_name = try mem.replaceOwned(u8, &self.arena.allocator, field.name, "_", "-"); + const field_name = try mem.replaceOwned(u8, self.arena.allocator(), field.name, "_", "-"); break :blk map.get(field_name); }; @@ -382,7 +383,7 @@ pub const Yaml = struct { fn parsePointer(self: *Yaml, comptime T: type, value: Value) Error!T { const ptr_info = @typeInfo(T).Pointer; - const arena = &self.arena.allocator; + const arena = self.arena.allocator(); switch (ptr_info.size) { .Slice => { |
