authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-04-02 00:00:42+02:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-04-02 16:12:08+02:00
log7a28c644aa8eb3d27dee113338af8278f8f6334f
treede1a483b9d9fa9224a50c94522da6bb3308b016c
parentd3ab0eb28de5a5a94fd4ef988dd4c4b0e3ddf927

new ArrayList API: fix everything else


18 files changed, 58 insertions(+), 59 deletions(-)

lib/std/build.zig+2-2
......@@ -1779,7 +1779,7 @@ pub const LibExeObjStep = struct {
17791779 const self = @fieldParentPtr(LibExeObjStep, "step", step);
17801780 const builder = self.builder;
17811781
1782 if (self.root_src == null and self.link_objects.len == 0) {
1782 if (self.root_src == null and self.link_objects.items.len == 0) {
17831783 warn("{}: linker needs 1 or more objects to link\n", .{self.step.name});
17841784 return error.NeedAnObject;
17851785 }
......@@ -1847,7 +1847,7 @@ pub const LibExeObjStep = struct {
18471847 }
18481848 }
18491849
1850 if (self.build_options_contents.len > 0) {
1850 if (self.build_options_contents.items.len > 0) {
18511851 const build_options_file = try fs.path.join(
18521852 builder.allocator,
18531853 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
lib/std/build/emit_raw.zig+1-1
......@@ -94,7 +94,7 @@ const BinaryElfOutput = struct {
9494
9595 sort.sort(*BinaryElfSegment, self.segments.span(), segmentSortCompare);
9696
97 if (self.segments.len > 0) {
97 if (self.segments.items.len > 0) {
9898 const firstSegment = self.segments.at(0);
9999 if (firstSegment.firstSection) |firstSection| {
100100 const diff = firstSection.elfOffset - firstSegment.elfOffset;
lib/std/coff.zig+1-1
......@@ -181,7 +181,7 @@ pub const Coff = struct {
181181 }
182182
183183 pub fn loadSections(self: *Coff) !void {
184 if (self.sections.len == self.coff_header.number_of_sections)
184 if (self.sections.items.len == self.coff_header.number_of_sections)
185185 return;
186186
187187 try self.sections.ensureCapacity(self.coff_header.number_of_sections);
lib/std/debug.zig+1-1
......@@ -1478,7 +1478,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14781478
14791479 var coff_section: *coff.Section = undefined;
14801480 const mod_index = for (self.sect_contribs) |sect_contrib| {
1481 if (sect_contrib.Section > self.coff.sections.len) continue;
1481 if (sect_contrib.Section > self.coff.sections.items.len) continue;
14821482 // Remember that SectionContribEntry.Section is 1-based.
14831483 coff_section = &self.coff.sections.span()[sect_contrib.Section - 1];
14841484
lib/std/fs.zig+3-3
......@@ -1440,9 +1440,9 @@ pub const Walker = struct {
14401440 /// a reference to the path.
14411441 pub fn next(self: *Walker) !?Entry {
14421442 while (true) {
1443 if (self.stack.len == 0) return null;
1443 if (self.stack.items.len == 0) return null;
14441444 // `top` becomes invalid after appending to `self.stack`.
1445 const top = &self.stack.span()[self.stack.len - 1];
1445 const top = &self.stack.span()[self.stack.items.len - 1];
14461446 const dirname_len = top.dirname_len;
14471447 if (try top.dir_it.next()) |base| {
14481448 self.name_buffer.shrink(dirname_len);
......@@ -1457,7 +1457,7 @@ pub const Walker = struct {
14571457 errdefer new_dir.close();
14581458 try self.stack.append(StackItem{
14591459 .dir_it = new_dir.iterate(),
1460 .dirname_len = self.name_buffer.len,
1460 .dirname_len = self.name_buffer.items.len,
14611461 });
14621462 }
14631463 }
lib/std/http/headers.zig+12-12
......@@ -139,7 +139,7 @@ pub const Headers = struct {
139139 pub fn clone(self: Self, allocator: *Allocator) !Self {
140140 var other = Headers.init(allocator);
141141 errdefer other.deinit();
142 try other.data.ensureCapacity(self.data.len);
142 try other.data.ensureCapacity(self.data.items.len);
143143 try other.index.initCapacity(self.index.entries.len);
144144 for (self.data.span()) |entry| {
145145 try other.append(entry.name, entry.value, entry.never_index);
......@@ -152,7 +152,7 @@ pub const Headers = struct {
152152 }
153153
154154 pub fn append(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void {
155 const n = self.data.len + 1;
155 const n = self.data.items.len + 1;
156156 try self.data.ensureCapacity(n);
157157 var entry: HeaderEntry = undefined;
158158 if (self.index.get(name)) |kv| {
......@@ -197,7 +197,7 @@ pub const Headers = struct {
197197 if (self.index.remove(name)) |kv| {
198198 var dex = &kv.value;
199199 // iterate backwards
200 var i = dex.len;
200 var i = dex.items.len;
201201 while (i > 0) {
202202 i -= 1;
203203 const data_index = dex.at(i);
......@@ -220,18 +220,18 @@ pub const Headers = struct {
220220 const removed = self.data.orderedRemove(i);
221221 const kv = self.index.get(removed.name).?;
222222 var dex = &kv.value;
223 if (dex.len == 1) {
223 if (dex.items.len == 1) {
224224 // was last item; delete the index
225225 _ = self.index.remove(kv.key);
226226 dex.deinit();
227227 removed.deinit();
228228 self.allocator.free(kv.key);
229229 } else {
230 dex.shrink(dex.len - 1);
230 dex.shrink(dex.items.len - 1);
231231 removed.deinit();
232232 }
233233 // if it was the last item; no need to rebuild index
234 if (i != self.data.len) {
234 if (i != self.data.items.len) {
235235 self.rebuild_index();
236236 }
237237 }
......@@ -242,18 +242,18 @@ pub const Headers = struct {
242242 const removed = self.data.swapRemove(i);
243243 const kv = self.index.get(removed.name).?;
244244 var dex = &kv.value;
245 if (dex.len == 1) {
245 if (dex.items.len == 1) {
246246 // was last item; delete the index
247247 _ = self.index.remove(kv.key);
248248 dex.deinit();
249249 removed.deinit();
250250 self.allocator.free(kv.key);
251251 } else {
252 dex.shrink(dex.len - 1);
252 dex.shrink(dex.items.len - 1);
253253 removed.deinit();
254254 }
255255 // if it was the last item; no need to rebuild index
256 if (i != self.data.len) {
256 if (i != self.data.items.len) {
257257 self.rebuild_index();
258258 }
259259 }
......@@ -277,7 +277,7 @@ pub const Headers = struct {
277277 pub fn get(self: Self, allocator: *Allocator, name: []const u8) !?[]const HeaderEntry {
278278 const dex = self.getIndices(name) orelse return null;
279279
280 const buf = try allocator.alloc(HeaderEntry, dex.len);
280 const buf = try allocator.alloc(HeaderEntry, dex.items.len);
281281 var n: usize = 0;
282282 for (dex.span()) |idx| {
283283 buf[n] = self.data.at(idx);
......@@ -301,7 +301,7 @@ pub const Headers = struct {
301301
302302 // adapted from mem.join
303303 const total_len = blk: {
304 var sum: usize = dex.len - 1; // space for separator(s)
304 var sum: usize = dex.items.len - 1; // space for separator(s)
305305 for (dex.span()) |idx|
306306 sum += self.data.at(idx).value.len;
307307 break :blk sum;
......@@ -330,7 +330,7 @@ pub const Headers = struct {
330330 var it = self.index.iterator();
331331 while (it.next()) |kv| {
332332 var dex = &kv.value;
333 dex.len = 0; // keeps capacity available
333 dex.items.len = 0; // keeps capacity available
334334 }
335335 }
336336 { // fill up indexes again; we know capacity is fine from before
lib/std/io/in_stream.zig+1-1
......@@ -54,7 +54,7 @@ pub fn InStream(
5454 /// and the `std.ArrayList` has exactly `max_append_size` bytes appended.
5555 pub fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void {
5656 try array_list.ensureCapacity(math.min(max_append_size, 4096));
57 const original_len = array_list.len;
57 const original_len = array_list.items.len;
5858 var start_index: usize = original_len;
5959 while (true) {
6060 array_list.expandToCapacity();
lib/std/json.zig+10-10
......@@ -1556,7 +1556,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
15561556 else => {},
15571557 }
15581558
1559 try arraylist.ensureCapacity(arraylist.len + 1);
1559 try arraylist.ensureCapacity(arraylist.items.len + 1);
15601560 const v = try parseInternal(ptrInfo.child, tok, tokens, options);
15611561 arraylist.appendAssumeCapacity(v);
15621562 }
......@@ -1874,7 +1874,7 @@ pub const Parser = struct {
18741874 try p.transition(&arena.allocator, input, s.i - 1, token);
18751875 }
18761876
1877 debug.assert(p.stack.len == 1);
1877 debug.assert(p.stack.items.len == 1);
18781878
18791879 return ValueTree{
18801880 .arena = arena,
......@@ -1888,7 +1888,7 @@ pub const Parser = struct {
18881888 switch (p.state) {
18891889 .ObjectKey => switch (token) {
18901890 .ObjectEnd => {
1891 if (p.stack.len == 1) {
1891 if (p.stack.items.len == 1) {
18921892 return;
18931893 }
18941894
......@@ -1907,8 +1907,8 @@ pub const Parser = struct {
19071907 },
19081908 },
19091909 .ObjectValue => {
1910 var object = &p.stack.items[p.stack.len - 2].Object;
1911 var key = p.stack.items[p.stack.len - 1].String;
1910 var object = &p.stack.items[p.stack.items.len - 2].Object;
1911 var key = p.stack.items[p.stack.items.len - 1].String;
19121912
19131913 switch (token) {
19141914 .ObjectBegin => {
......@@ -1950,11 +1950,11 @@ pub const Parser = struct {
19501950 }
19511951 },
19521952 .ArrayValue => {
1953 var array = &p.stack.items[p.stack.len - 1].Array;
1953 var array = &p.stack.items[p.stack.items.len - 1].Array;
19541954
19551955 switch (token) {
19561956 .ArrayEnd => {
1957 if (p.stack.len == 1) {
1957 if (p.stack.items.len == 1) {
19581958 return;
19591959 }
19601960
......@@ -2021,12 +2021,12 @@ pub const Parser = struct {
20212021 }
20222022
20232023 fn pushToParent(p: *Parser, value: *const Value) !void {
2024 switch (p.stack.span()[p.stack.len - 1]) {
2024 switch (p.stack.span()[p.stack.items.len - 1]) {
20252025 // Object Parent -> [ ..., object, <key>, value ]
20262026 Value.String => |key| {
20272027 _ = p.stack.pop();
20282028
2029 var object = &p.stack.items[p.stack.len - 1].Object;
2029 var object = &p.stack.items[p.stack.items.len - 1].Object;
20302030 _ = try object.put(key, value.*);
20312031 p.state = .ObjectKey;
20322032 },
......@@ -2165,7 +2165,7 @@ test "json.parser.dynamic" {
21652165 testing.expect(animated.Bool == false);
21662166
21672167 const array_of_object = image.Object.get("ArrayOfObject").?.value;
2168 testing.expect(array_of_object.Array.len == 1);
2168 testing.expect(array_of_object.Array.items.len == 1);
21692169
21702170 const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
21712171 testing.expect(mem.eql(u8, obj0.String, "m"));
lib/std/math/big/rational.zig-1
......@@ -4,7 +4,6 @@ const math = std.math;
44const mem = std.mem;
55const testing = std.testing;
66const Allocator = mem.Allocator;
7const ArrayList = std.ArrayList;
87
98const bn = @import("int.zig");
109const Limb = bn.Limb;
lib/std/net.zig+8-8
......@@ -509,7 +509,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
509509
510510 try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
511511
512 result.addrs = try arena.alloc(Address, lookup_addrs.len);
512 result.addrs = try arena.alloc(Address, lookup_addrs.items.len);
513513 if (!canon.isNull()) {
514514 result.canon_name = canon.toOwnedSlice();
515515 }
......@@ -554,7 +554,7 @@ fn linuxLookupName(
554554 return name_err;
555555 } else {
556556 try linuxLookupNameFromHosts(addrs, canon, name, family, port);
557 if (addrs.len == 0) {
557 if (addrs.items.len == 0) {
558558 try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
559559 }
560560 }
......@@ -562,11 +562,11 @@ fn linuxLookupName(
562562 try canon.resize(0);
563563 try linuxLookupNameFromNull(addrs, family, flags, port);
564564 }
565 if (addrs.len == 0) return error.UnknownHostName;
565 if (addrs.items.len == 0) return error.UnknownHostName;
566566
567567 // No further processing is needed if there are fewer than 2
568568 // results or if there are only IPv4 results.
569 if (addrs.len == 1 or family == os.AF_INET) return;
569 if (addrs.items.len == 1 or family == os.AF_INET) return;
570570 const all_ip4 = for (addrs.span()) |addr| {
571571 if (addr.addr.any.family != os.AF_INET) break false;
572572 } else true;
......@@ -908,7 +908,7 @@ fn linuxLookupNameFromDnsSearch(
908908 canon.shrink(canon_name.len + 1);
909909 try canon.appendSlice(tok);
910910 try linuxLookupNameFromDns(addrs, canon, canon.span(), family, rc, port);
911 if (addrs.len != 0) return;
911 if (addrs.items.len != 0) return;
912912 }
913913
914914 canon.shrink(canon_name.len);
......@@ -967,7 +967,7 @@ fn linuxLookupNameFromDns(
967967 dnsParse(ap[i], ctx, dnsParseCallback) catch {};
968968 }
969969
970 if (addrs.len != 0) return;
970 if (addrs.items.len != 0) return;
971971 if (ap[0].len < 4 or (ap[0][3] & 15) == 2) return error.TemporaryNameServerFailure;
972972 if ((ap[0][3] & 15) == 0) return error.UnknownHostName;
973973 if ((ap[0][3] & 15) == 3) return;
......@@ -1049,7 +1049,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
10491049 }
10501050 }
10511051
1052 if (rc.ns.len == 0) {
1052 if (rc.ns.items.len == 0) {
10531053 return linuxLookupNameFromNumericUnspec(&rc.ns, "127.0.0.1", 53);
10541054 }
10551055}
......@@ -1078,7 +1078,7 @@ fn resMSendRc(
10781078 var ns_list = std.ArrayList(Address).init(rc.ns.allocator);
10791079 defer ns_list.deinit();
10801080
1081 try ns_list.resize(rc.ns.len);
1081 try ns_list.resize(rc.ns.items.len);
10821082 const ns = ns_list.span();
10831083
10841084 for (rc.ns.span()) |iplit, i| {
lib/std/special/build_runner.zig+1-1
......@@ -171,7 +171,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
171171 \\
172172 );
173173
174 if (builder.available_options_list.len == 0) {
174 if (builder.available_options_list.items.len == 0) {
175175 try out_stream.print(" (none)\n", .{});
176176 } else {
177177 for (builder.available_options_list.span()) |option| {
lib/std/unicode.zig+2-2
......@@ -475,7 +475,7 @@ pub fn utf16leToUtf8Alloc(allocator: *mem.Allocator, utf16le: []const u16) ![]u8
475475 var it = Utf16LeIterator.init(utf16le);
476476 while (try it.nextCodepoint()) |codepoint| {
477477 const utf8_len = utf8CodepointSequenceLength(codepoint) catch unreachable;
478 try result.resize(result.len + utf8_len);
478 try result.resize(result.items.len + utf8_len);
479479 assert((utf8Encode(codepoint, result.items[out_index..]) catch unreachable) == utf8_len);
480480 out_index += utf8_len;
481481 }
......@@ -571,7 +571,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u
571571 }
572572 }
573573
574 const len = result.len;
574 const len = result.items.len;
575575 try result.append(0);
576576 return result.toOwnedSlice()[0..len :0];
577577}
src-self-hosted/libc_installation.zig+3-3
......@@ -268,7 +268,7 @@ pub const LibCInstallation = struct {
268268 try search_paths.append(line);
269269 }
270270 }
271 if (search_paths.len == 0) {
271 if (search_paths.items.len == 0) {
272272 return error.CCompilerCannotFindHeaders;
273273 }
274274
......@@ -276,9 +276,9 @@ pub const LibCInstallation = struct {
276276 const sys_include_dir_example_file = if (is_windows) "sys\\types.h" else "sys/errno.h";
277277
278278 var path_i: usize = 0;
279 while (path_i < search_paths.len) : (path_i += 1) {
279 while (path_i < search_paths.items.len) : (path_i += 1) {
280280 // search in reverse order
281 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
281 const search_path_untrimmed = search_paths.at(search_paths.items.len - path_i - 1);
282282 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
283283 var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) {
284284 error.FileNotFound,
src-self-hosted/stage2.zig+2-2
......@@ -239,7 +239,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
239239 }
240240
241241 if (stdin_flag) {
242 if (input_files.len != 0) {
242 if (input_files.items.len != 0) {
243243 try stderr.writeAll("cannot use --stdin with positional arguments\n");
244244 process.exit(1);
245245 }
......@@ -273,7 +273,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
273273 return;
274274 }
275275
276 if (input_files.len == 0) {
276 if (input_files.items.len == 0) {
277277 try stderr.writeAll("expected at least one source file argument\n");
278278 process.exit(1);
279279 }
src-self-hosted/translate_c.zig+3-3
......@@ -4309,7 +4309,7 @@ fn makeRestorePoint(c: *Context) RestorePoint {
43094309 return RestorePoint{
43104310 .c = c,
43114311 .token_index = c.tree.tokens.len,
4312 .src_buf_index = c.source_buffer.len,
4312 .src_buf_index = c.source_buffer.items.len,
43134313 };
43144314}
43154315
......@@ -4771,11 +4771,11 @@ fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenInd
47714771
47724772fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {
47734773 assert(token_id != .Invalid);
4774 const start_index = c.source_buffer.len;
4774 const start_index = c.source_buffer.items.len;
47754775 errdefer c.source_buffer.shrink(start_index);
47764776
47774777 try c.source_buffer.outStream().print(format, args);
4778 const end_index = c.source_buffer.len;
4778 const end_index = c.source_buffer.items.len;
47794779 const token_index = c.tree.tokens.len;
47804780 const new_token = try c.tree.tokens.addOne();
47814781 errdefer c.tree.tokens.shrink(token_index);
test/standalone/brace_expansion/main.zig+2-2
......@@ -113,7 +113,7 @@ fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
113113
114114fn expandString(input: []const u8, output: *ArrayListSentineled(u8, 0)) !void {
115115 const tokens = try tokenize(input);
116 if (tokens.len == 1) {
116 if (tokens.items.len == 1) {
117117 return output.resize(0);
118118 }
119119
......@@ -142,7 +142,7 @@ fn expandString(input: []const u8, output: *ArrayListSentineled(u8, 0)) !void {
142142const ExpandNodeError = error{OutOfMemory};
143143
144144fn expandNode(node: Node, output: *ArrayList(ArrayListSentineled(u8, 0))) ExpandNodeError!void {
145 assert(output.len == 0);
145 assert(output.items.len == 0);
146146 switch (node) {
147147 Node.Scalar => |scalar| {
148148 try output.append(try ArrayListSentineled(u8, 0).init(global_allocator, scalar));
test/tests.zig+2-2
......@@ -864,13 +864,13 @@ pub const CompileErrorContext = struct {
864864 var err_iter = ErrLineIter.init(stderr);
865865 var i: usize = 0;
866866 ok = while (err_iter.next()) |line| : (i += 1) {
867 if (i >= self.case.expected_errors.len) break false;
867 if (i >= self.case.expected_errors.items.len) break false;
868868 const expected = self.case.expected_errors.at(i);
869869 if (mem.indexOf(u8, line, expected) == null) break false;
870870 continue;
871871 } else true;
872872
873 ok = ok and i == self.case.expected_errors.len;
873 ok = ok and i == self.case.expected_errors.items.len;
874874
875875 if (!ok) {
876876 warn("\n======== Expected these compile errors: ========\n", .{});
tools/merge_anal_dumps.zig+4-4
......@@ -194,7 +194,7 @@ const Dump = struct {
194194 for (other_files) |other_file, i| {
195195 const gop = try self.file_map.getOrPut(other_file.String);
196196 if (!gop.found_existing) {
197 gop.kv.value = self.file_list.len;
197 gop.kv.value = self.file_list.items.len;
198198 try self.file_list.append(other_file.String);
199199 }
200200 try other_file_to_mine.putNoClobber(i, gop.kv.value);
......@@ -213,7 +213,7 @@ const Dump = struct {
213213 };
214214 const gop = try self.node_map.getOrPut(other_node);
215215 if (!gop.found_existing) {
216 gop.kv.value = self.node_list.len;
216 gop.kv.value = self.node_list.items.len;
217217 try self.node_list.append(other_node);
218218 }
219219 try other_ast_node_to_mine.putNoClobber(i, gop.kv.value);
......@@ -243,7 +243,7 @@ const Dump = struct {
243243 };
244244 const gop = try self.error_map.getOrPut(other_error);
245245 if (!gop.found_existing) {
246 gop.kv.value = self.error_list.len;
246 gop.kv.value = self.error_list.items.len;
247247 try self.error_list.append(other_error);
248248 }
249249 try other_error_to_mine.putNoClobber(i, gop.kv.value);
......@@ -304,7 +304,7 @@ const Dump = struct {
304304 ) !void {
305305 const gop = try self.type_map.getOrPut(other_type);
306306 if (!gop.found_existing) {
307 gop.kv.value = self.type_list.len;
307 gop.kv.value = self.type_list.items.len;
308308 try self.type_list.append(other_type);
309309 }
310310 try other_types_to_mine.putNoClobber(other_type_index, gop.kv.value);