authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-14 00:56:14 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-14 00:56:14 -07:00
loge970ba3719c15792529200a1df3d64277b343687
tree7be4a7ed4e60481e24bd6fbe059f531c01996a5b
parent0ee7496fe5f5f05afbb00349d8cbc23c37b0a167

fix usage of std.ArrayList


9 files changed, 29 insertions(+), 29 deletions(-)

src/cmd/fetch.zig+9-9
...@@ -26,14 +26,14 @@ pub fn execute(args: [][]u8) !void {...@@ -26,14 +26,14 @@ pub fn execute(args: [][]u8) !void {
26 };26 };
27 const top_module = try common.collect_deps_deep(dir, "zig.mod", &options);27 const top_module = try common.collect_deps_deep(dir, "zig.mod", &options);
2828
29 const list = &std.ArrayList(u.Module).init(gpa);29 var list = std.ArrayList(u.Module).init(gpa);
30 try common.collect_pkgs(top_module, list);30 try common.collect_pkgs(top_module, &list);
3131
32 try create_depszig(dir, top_module, list);32 try create_depszig(dir, top_module, &list);
3333
34 if (bootstrap) return;34 if (bootstrap) return;
3535
36 try create_lockfile(list, dir);36 try create_lockfile(&list, dir);
3737
38 try diff_lockfile();38 try diff_lockfile();
39}39}
...@@ -92,14 +92,14 @@ pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u....@@ -92,14 +92,14 @@ pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u.
92 try w.writeAll("};\n\n");92 try w.writeAll("};\n\n");
9393
94 try w.writeAll("pub const package_data = struct {\n");94 try w.writeAll("pub const package_data = struct {\n");
95 const duped = &std.ArrayList(u.Module).init(gpa);95 var duped = std.ArrayList(u.Module).init(gpa);
96 for (list.items) |mod| {96 for (list.items) |mod| {
97 if (mod.is_sys_lib) {97 if (mod.is_sys_lib) {
98 continue;98 continue;
99 }99 }
100 try duped.append(mod);100 try duped.append(mod);
101 }101 }
102 try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa));102 try print_pkg_data_to(w, &duped, &std.ArrayList(u.Module).init(gpa));
103 try w.writeAll("};\n\n");103 try w.writeAll("};\n\n");
104104
105 try w.writeAll("pub const packages = ");105 try w.writeAll("pub const packages = ");
...@@ -149,15 +149,15 @@ fn diff_lockfile() !void {...@@ -149,15 +149,15 @@ fn diff_lockfile() !void {
149 if (std.mem.startsWith(u8, line, "@@")) break;149 if (std.mem.startsWith(u8, line, "@@")) break;
150 }150 }
151151
152 const rems = &std.ArrayList(string).init(gpa);152 var rems = std.ArrayList(string).init(gpa);
153 const adds = &std.ArrayList(string).init(gpa);153 var adds = std.ArrayList(string).init(gpa);
154 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| {154 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| {
155 if (line[0] == ' ') continue;155 if (line[0] == ' ') continue;
156 if (line[0] == '-') try rems.append(line[1..]);156 if (line[0] == '-') try rems.append(line[1..]);
157 if (line[0] == '+') if (line[1] == '2') continue else try adds.append(line[1..]);157 if (line[0] == '+') if (line[1] == '2') continue else try adds.append(line[1..]);
158 }158 }
159159
160 const changes = &std.StringHashMap(DiffChange).init(gpa);160 var changes = std.StringHashMap(DiffChange).init(gpa);
161161
162 var i: usize = 0;162 var i: usize = 0;
163 while (i < rems.items.len) {163 while (i < rems.items.len) {
src/cmd/sum.zig+2-2
...@@ -24,8 +24,8 @@ pub fn execute(args: [][]u8) !void {...@@ -24,8 +24,8 @@ pub fn execute(args: [][]u8) !void {
24 const w = f.writer();24 const w = f.writer();
2525
26 //26 //
27 const module_list = &std.ArrayList(u.Module).init(gpa);27 var module_list = std.ArrayList(u.Module).init(gpa);
28 try common.collect_pkgs(top_module, module_list);28 try common.collect_pkgs(top_module, &module_list);
2929
30 for (module_list.items) |m| {30 for (module_list.items) |m| {
31 if (m.clean_path.len == 0) {31 if (m.clean_path.len == 0) {
src/cmd/zpm/search.zig+1-1
...@@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void {...@@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void {
19 const url = try std.mem.join(gpa, "/", &.{ zpm.server_root, "packages" });19 const url = try std.mem.join(gpa, "/", &.{ zpm.server_root, "packages" });
20 const val = try zpm.server_fetch(url);20 const val = try zpm.server_fetch(url);
2121
22 const arr = &std.ArrayList(zpm.Package).init(gpa);22 var arr = std.ArrayList(zpm.Package).init(gpa);
23 defer arr.deinit();23 defer arr.deinit();
2424
25 for (val.Array) |item| {25 for (val.Array) |item| {
src/common.zig+3-3
...@@ -30,7 +30,7 @@ pub const CollectOptions = struct {...@@ -30,7 +30,7 @@ pub const CollectOptions = struct {
30pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: *CollectOptions) !u.Module {30pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: *CollectOptions) !u.Module {
31 const m = try u.ModFile.init(gpa, mpath);31 const m = try u.ModFile.init(gpa, mpath);
32 try options.init();32 try options.init();
33 const moduledeps = &std.ArrayList(u.Module).init(gpa);33 var moduledeps = std.ArrayList(u.Module).init(gpa);
34 defer moduledeps.deinit();34 defer moduledeps.deinit();
35 try std.fs.cwd().makePath(".zigmod/deps/files");35 try std.fs.cwd().makePath(".zigmod/deps/files");
36 if (m.root_files.len > 0) {36 if (m.root_files.len > 0) {
...@@ -56,7 +56,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: *CollectOp...@@ -56,7 +56,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: *CollectOp
5656
57pub fn collect_deps(dir: []const u8, mpath: []const u8, options: *CollectOptions) anyerror!u.Module {57pub fn collect_deps(dir: []const u8, mpath: []const u8, options: *CollectOptions) anyerror!u.Module {
58 const m = try u.ModFile.init(gpa, mpath);58 const m = try u.ModFile.init(gpa, mpath);
59 const moduledeps = &std.ArrayList(u.Module).init(gpa);59 var moduledeps = std.ArrayList(u.Module).init(gpa);
60 defer moduledeps.deinit();60 defer moduledeps.deinit();
61 if (m.files.len > 0) {61 if (m.files.len > 0) {
62 try moduledeps.append(try add_files_package(m.id, m.files, m.name));62 try moduledeps.append(try add_files_package(m.id, m.files, m.name));
...@@ -336,7 +336,7 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_...@@ -336,7 +336,7 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_
336}336}
337337
338pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 {338pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 {
339 const list = &std.ArrayList([4][]const u8).init(gpa);339 var list = std.ArrayList([4][]const u8).init(gpa);
340 const max = std.math.maxInt(usize);340 const max = std.math.maxInt(usize);
341 const f = try std.fs.cwd().openFile(path, .{});341 const f = try std.fs.cwd().openFile(path, .{});
342 const r = f.reader();342 const r = f.reader();
src/main.zig+1-1
...@@ -53,7 +53,7 @@ pub fn main() !void {...@@ -53,7 +53,7 @@ pub fn main() !void {
53 }53 }
54 }54 }
5555
56 var sub_cmd_args = &std.ArrayList([]const u8).init(gpa);56 var sub_cmd_args = std.ArrayList([]const u8).init(gpa);
57 try sub_cmd_args.append(try std.fmt.allocPrint(gpa, "zigmod-{s}", .{args[0]}));57 try sub_cmd_args.append(try std.fmt.allocPrint(gpa, "zigmod-{s}", .{args[0]}));
58 for (args[1..]) |item| {58 for (args[1..]) |item| {
59 try sub_cmd_args.append(item);59 try sub_cmd_args.append(item);
src/util/funcs.zig+3-3
...@@ -33,7 +33,7 @@ pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {...@@ -33,7 +33,7 @@ pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {
33}33}
3434
35pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {35pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {
36 const list = &std.ArrayList([]const u8).init(gpa);36 var list = std.ArrayList([]const u8).init(gpa);
37 defer list.deinit();37 defer list.deinit();
38 const iter = &std.mem.split(in, delim);38 const iter = &std.mem.split(in, delim);
39 while (iter.next()) |str| {39 while (iter.next()) |str| {
...@@ -90,7 +90,7 @@ pub fn trim_suffix(in: []const u8, suffix: []const u8) []const u8 {...@@ -90,7 +90,7 @@ pub fn trim_suffix(in: []const u8, suffix: []const u8) []const u8 {
90}90}
9191
92pub fn repeat(s: []const u8, times: i32) ![]const u8 {92pub fn repeat(s: []const u8, times: i32) ![]const u8 {
93 const list = &std.ArrayList([]const u8).init(gpa);93 var list = std.ArrayList([]const u8).init(gpa);
94 var i: i32 = 0;94 var i: i32 = 0;
95 while (i < times) : (i += 1) {95 while (i < times) : (i += 1) {
96 try list.append(s);96 try list.append(s);
...@@ -175,7 +175,7 @@ pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {...@@ -175,7 +175,7 @@ pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {
175}175}
176176
177pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {177pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {
178 const list = &std.ArrayList([]const u8).init(gpa);178 var list = std.ArrayList([]const u8).init(gpa);
179 defer list.deinit();179 defer list.deinit();
180 for (input) |item| {180 for (input) |item| {
181 if (!std.mem.eql(u8, item, search)) {181 if (!std.mem.eql(u8, item, search)) {
src/util/modfile.zig+1-1
...@@ -68,7 +68,7 @@ pub const ModFile = struct {...@@ -68,7 +68,7 @@ pub const ModFile = struct {
68 }68 }
6969
70 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) anyerror![]u.Dep {70 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) anyerror![]u.Dep {
71 const dep_list = &std.ArrayList(u.Dep).init(alloc);71 var dep_list = std.ArrayList(u.Dep).init(alloc);
72 if (mapping.get(prop)) |dep_seq| {72 if (mapping.get(prop)) |dep_seq| {
73 if (dep_seq == .sequence) {73 if (dep_seq == .sequence) {
74 for (dep_seq.sequence) |item| {74 for (dep_seq.sequence) |item| {
src/util/module.zig+4-4
...@@ -25,7 +25,7 @@ pub const Module = struct {...@@ -25,7 +25,7 @@ pub const Module = struct {
25 dep: ?u.Dep,25 dep: ?u.Dep,
2626
27 pub fn from(dep: u.Dep, dir: []const u8, options: *common.CollectOptions) !Module {27 pub fn from(dep: u.Dep, dir: []const u8, options: *common.CollectOptions) !Module {
28 const moddeps = &std.ArrayList(Module).init(gpa);28 var moddeps = std.ArrayList(Module).init(gpa);
29 defer moddeps.deinit();29 defer moddeps.deinit();
30 for (dep.deps) |*d| {30 for (dep.deps) |*d| {
31 if (try common.get_module_from_dep(d, dir, dep.name, options)) |founddep| {31 if (try common.get_module_from_dep(d, dir, dep.name, options)) |founddep| {
...@@ -54,11 +54,11 @@ pub const Module = struct {...@@ -54,11 +54,11 @@ pub const Module = struct {
54 }54 }
5555
56 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {56 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {
57 const file_list_1 = &std.ArrayList([]const u8).init(gpa);57 var file_list_1 = std.ArrayList([]const u8).init(gpa);
58 defer file_list_1.deinit();58 defer file_list_1.deinit();
59 try u.file_list(try u.concat(&.{ cdpath, "/", self.clean_path }), file_list_1);59 try u.file_list(try u.concat(&.{ cdpath, "/", self.clean_path }), &file_list_1);
6060
61 const file_list_2 = &std.ArrayList([]const u8).init(gpa);61 var file_list_2 = std.ArrayList([]const u8).init(gpa);
62 defer file_list_2.deinit();62 defer file_list_2.deinit();
63 for (file_list_1.items) |item| {63 for (file_list_1.items) |item| {
64 const _a = u.trim_prefix(item, cdpath);64 const _a = u.trim_prefix(item, cdpath);
src/util/yaml.zig+5-5
...@@ -112,7 +112,7 @@ pub const Mapping = struct {...@@ -112,7 +112,7 @@ pub const Mapping = struct {
112 }112 }
113113
114 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {114 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {
115 const list = &std.ArrayList([]const u8).init(alloc);115 var list = std.ArrayList([]const u8).init(alloc);
116 defer list.deinit();116 defer list.deinit();
117 if (self.get(k)) |val| {117 if (self.get(k)) |val| {
118 if (val == .sequence) {118 if (val == .sequence) {
...@@ -154,7 +154,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {...@@ -154,7 +154,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
154154
155 _ = c.yaml_parser_set_input_string(&parser, input.ptr, input.len);155 _ = c.yaml_parser_set_input_string(&parser, input.ptr, input.len);
156156
157 const all_events = &std.ArrayList(Token).init(alloc);157 var all_events = std.ArrayList(Token).init(alloc);
158 var event: Token = undefined;158 var event: Token = undefined;
159 while (true) {159 while (true) {
160 const p = c.yaml_parser_parse(&parser, &event);160 const p = c.yaml_parser_parse(&parser, &event);
...@@ -220,7 +220,7 @@ fn parse_item(p: *Parser, start: ?Token) Error!Item {...@@ -220,7 +220,7 @@ fn parse_item(p: *Parser, start: ?Token) Error!Item {
220}220}
221221
222fn parse_stream(p: *Parser) Error!Stream {222fn parse_stream(p: *Parser) Error!Stream {
223 const res = &std.ArrayList(Document).init(p.alloc);223 var res = std.ArrayList(Document).init(p.alloc);
224 defer res.deinit();224 defer res.deinit();
225225
226 while (true) {226 while (true) {
...@@ -250,7 +250,7 @@ fn parse_document(p: *Parser) Error!Document {...@@ -250,7 +250,7 @@ fn parse_document(p: *Parser) Error!Document {
250}250}
251251
252fn parse_mapping(p: *Parser) Error!Mapping {252fn parse_mapping(p: *Parser) Error!Mapping {
253 const res = &std.ArrayList(Key).init(p.alloc);253 var res = std.ArrayList(Key).init(p.alloc);
254 defer res.deinit();254 defer res.deinit();
255255
256 while (true) {256 while (true) {
...@@ -279,7 +279,7 @@ fn parse_value(p: *Parser) Error!Value {...@@ -279,7 +279,7 @@ fn parse_value(p: *Parser) Error!Value {
279}279}
280280
281fn parse_sequence(p: *Parser) Error!Sequence {281fn parse_sequence(p: *Parser) Error!Sequence {
282 const res = &std.ArrayList(Item).init(p.alloc);282 var res = std.ArrayList(Item).init(p.alloc);
283 defer res.deinit();283 defer res.deinit();
284284
285 while (true) {285 while (true) {