authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-04-11 21:06:56+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-11 20:40:34-04:00
logdbc00e24247da16ac584bb9e92b5ccf04647c3b9
treea73219b06cb0ead18b93289975257f2f498f5dd4
parent3c34c313cf999238753b34f01b0437a552fb3be0

ArrayList: remove old (before span) API


7 files changed, 29 insertions(+), 97 deletions(-)

build.zig+4-4
......@@ -136,14 +136,14 @@ pub fn build(b: *Builder) !void {
136136}
137137
138138fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
139 for (dep.libdirs.toSliceConst()) |lib_dir| {
139 for (dep.libdirs.items) |lib_dir| {
140140 lib_exe_obj.addLibPath(lib_dir);
141141 }
142142 const lib_dir = fs.path.join(
143143 b.allocator,
144144 &[_][]const u8{ dep.prefix, "lib" },
145145 ) catch unreachable;
146 for (dep.system_libs.toSliceConst()) |lib| {
146 for (dep.system_libs.items) |lib| {
147147 const static_bare_name = if (mem.eql(u8, lib, "curses"))
148148 @as([]const u8, "libncurses.a")
149149 else
......@@ -159,10 +159,10 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
159159 lib_exe_obj.linkSystemLibrary(lib);
160160 }
161161 }
162 for (dep.libs.toSliceConst()) |lib| {
162 for (dep.libs.items) |lib| {
163163 lib_exe_obj.addObjectFile(lib);
164164 }
165 for (dep.includes.toSliceConst()) |include_path| {
165 for (dep.includes.items) |include_path| {
166166 lib_exe_obj.addIncludeDir(include_path);
167167 }
168168}
lib/std/array_list.zig+9-77
......@@ -57,37 +57,13 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
5757 return self.items;
5858 }
5959
60 /// Deprecated: use `items` field directly.
61 pub fn toSlice(self: Self) Slice {
62 return self.items;
63 }
64
65 /// Deprecated: use `items` field directly.
66 pub fn toSliceConst(self: Self) SliceConst {
67 return self.items;
68 }
69
70 /// Deprecated: use `list.items[i]`.
71 pub fn at(self: Self, i: usize) T {
72 return self.items[i];
73 }
74
75 /// Deprecated: use `&list.items[i]`.
76 pub fn ptrAt(self: Self, i: usize) *T {
77 return &self.items[i];
78 }
79
80 /// Deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`.
81 pub fn setOrError(self: Self, i: usize, item: T) !void {
82 if (i >= self.items.len) return error.OutOfBounds;
83 self.items[i] = item;
84 }
85
86 /// Deprecated: use `list.items[i] = item`.
87 pub fn set(self: *Self, i: usize, item: T) void {
88 assert(i < self.items.len);
89 self.items[i] = item;
90 }
60 pub const toSlice = @compileError("deprecated: use `items` field directly");
61 pub const toSliceConst = @compileError("deprecated: use `items` field directly");
62 pub const at = @compileError("deprecated: use `list.items[i]`");
63 pub const ptrAt = @compileError("deprecated: use `&list.items[i]`");
64 pub const setOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`");
65 pub const set = @compileError("deprecated: use `list.items[i] = item`");
66 pub const swapRemoveOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`");
9167
9268 /// ArrayList takes ownership of the passed in slice. The slice must have been
9369 /// allocated with `allocator`.
......@@ -167,12 +143,6 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
167143 return old_item;
168144 }
169145
170 /// Deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`.
171 pub fn swapRemoveOrError(self: *Self, i: usize) !T {
172 if (i >= self.items.len) return error.OutOfBounds;
173 return self.swapRemove(i);
174 }
175
176146 /// Append the slice of items to the list. Allocates more
177147 /// memory as necessary.
178148 pub fn appendSlice(self: *Self, items: SliceConst) !void {
......@@ -308,9 +278,6 @@ test "std.ArrayList.basic" {
308278 var list = ArrayList(i32).init(testing.allocator);
309279 defer list.deinit();
310280
311 // setting on empty list is out of bounds
312 testing.expectError(error.OutOfBounds, list.setOrError(0, 1));
313
314281 {
315282 var i: usize = 0;
316283 while (i < 10) : (i += 1) {
......@@ -329,10 +296,6 @@ test "std.ArrayList.basic" {
329296 testing.expect(v == @intCast(i32, i + 1));
330297 }
331298
332 for (list.toSliceConst()) |v, i| {
333 testing.expect(v == @intCast(i32, i + 1));
334 }
335
336299 testing.expect(list.pop() == 10);
337300 testing.expect(list.items.len == 9);
338301
......@@ -347,11 +310,8 @@ test "std.ArrayList.basic" {
347310 testing.expect(list.items.len == 9);
348311
349312 // can only set on indices < self.items.len
350 list.set(7, 33);
351 list.set(8, 42);
352
353 testing.expectError(error.OutOfBounds, list.setOrError(9, 99));
354 testing.expectError(error.OutOfBounds, list.setOrError(10, 123));
313 list.items[7] = 33;
314 list.items[8] = 42;
355315
356316 testing.expect(list.pop() == 42);
357317 testing.expect(list.pop() == 33);
......@@ -428,34 +388,6 @@ test "std.ArrayList.swapRemove" {
428388 testing.expect(list.items.len == 4);
429389}
430390
431test "std.ArrayList.swapRemoveOrError" {
432 var list = ArrayList(i32).init(testing.allocator);
433 defer list.deinit();
434
435 // Test just after initialization
436 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
437
438 // Test after adding one item and remote it
439 try list.append(1);
440 testing.expect((try list.swapRemoveOrError(0)) == 1);
441 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
442
443 // Test after adding two items and remote both
444 try list.append(1);
445 try list.append(2);
446 testing.expect((try list.swapRemoveOrError(1)) == 2);
447 testing.expect((try list.swapRemoveOrError(0)) == 1);
448 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
449
450 // Test out of bounds with one item
451 try list.append(1);
452 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(1));
453
454 // Test out of bounds with two items
455 try list.append(2);
456 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(2));
457}
458
459391test "std.ArrayList.insert" {
460392 var list = ArrayList(i32).init(testing.allocator);
461393 defer list.deinit();
lib/std/fs/test.zig+1-1
......@@ -158,7 +158,7 @@ const FileLockTestContext = struct {
158158fn run_lock_file_test(contexts: []FileLockTestContext) !void {
159159 var threads = std.ArrayList(*std.Thread).init(std.testing.allocator);
160160 defer {
161 for (threads.toSlice()) |thread| {
161 for (threads.items) |thread| {
162162 thread.wait();
163163 }
164164 threads.deinit();
lib/std/http/headers.zig+8-8
......@@ -200,7 +200,7 @@ pub const Headers = struct {
200200 var i = dex.items.len;
201201 while (i > 0) {
202202 i -= 1;
203 const data_index = dex.at(i);
203 const data_index = dex.items[i];
204204 const removed = self.data.orderedRemove(data_index);
205205 assert(mem.eql(u8, removed.name, name));
206206 removed.deinit();
......@@ -260,7 +260,7 @@ pub const Headers = struct {
260260
261261 /// Access the header at the specified index.
262262 pub fn at(self: Self, i: usize) HeaderEntry {
263 return self.data.at(i);
263 return self.data.items[i];
264264 }
265265
266266 /// Returns a list of indices containing headers with the given name.
......@@ -280,7 +280,7 @@ pub const Headers = struct {
280280 const buf = try allocator.alloc(HeaderEntry, dex.items.len);
281281 var n: usize = 0;
282282 for (dex.span()) |idx| {
283 buf[n] = self.data.at(idx);
283 buf[n] = self.data.items[idx];
284284 n += 1;
285285 }
286286 return buf;
......@@ -303,18 +303,18 @@ pub const Headers = struct {
303303 const total_len = blk: {
304304 var sum: usize = dex.items.len - 1; // space for separator(s)
305305 for (dex.span()) |idx|
306 sum += self.data.at(idx).value.len;
306 sum += self.data.items[idx].value.len;
307307 break :blk sum;
308308 };
309309
310310 const buf = try allocator.alloc(u8, total_len);
311311 errdefer allocator.free(buf);
312312
313 const first_value = self.data.at(dex.at(0)).value;
313 const first_value = self.data.items[dex.items[0]].value;
314314 mem.copy(u8, buf, first_value);
315315 var buf_index: usize = first_value.len;
316 for (dex.toSlice()[1..]) |idx| {
317 const value = self.data.at(idx).value;
316 for (dex.items[1..]) |idx| {
317 const value = self.data.items[idx].value;
318318 buf[buf_index] = ',';
319319 buf_index += 1;
320320 mem.copy(u8, buf[buf_index..], value);
......@@ -342,7 +342,7 @@ pub const Headers = struct {
342342 }
343343
344344 pub fn sort(self: *Self) void {
345 std.sort.sort(HeaderEntry, self.data.toSlice(), HeaderEntry.compare);
345 std.sort.sort(HeaderEntry, self.data.items, HeaderEntry.compare);
346346 self.rebuild_index();
347347 }
348348
lib/std/json.zig+5-5
......@@ -1879,7 +1879,7 @@ pub const Parser = struct {
18791879
18801880 return ValueTree{
18811881 .arena = arena,
1882 .root = p.stack.at(0),
1882 .root = p.stack.items[0],
18831883 };
18841884 }
18851885
......@@ -2168,7 +2168,7 @@ test "json.parser.dynamic" {
21682168 const array_of_object = image.Object.get("ArrayOfObject").?.value;
21692169 testing.expect(array_of_object.Array.items.len == 1);
21702170
2171 const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
2171 const obj0 = array_of_object.Array.items[0].Object.get("n").?.value;
21722172 testing.expect(mem.eql(u8, obj0.String, "m"));
21732173
21742174 const double = image.Object.get("double").?.value;
......@@ -2222,8 +2222,8 @@ test "write json then parse it" {
22222222 testing.expect(tree.root.Object.get("f").?.value.Bool == false);
22232223 testing.expect(tree.root.Object.get("t").?.value.Bool == true);
22242224 testing.expect(tree.root.Object.get("int").?.value.Integer == 1234);
2225 testing.expect(tree.root.Object.get("array").?.value.Array.at(0).Null == {});
2226 testing.expect(tree.root.Object.get("array").?.value.Array.at(1).Float == 12.34);
2225 testing.expect(tree.root.Object.get("array").?.value.Array.items[0].Null == {});
2226 testing.expect(tree.root.Object.get("array").?.value.Array.items[1].Float == 12.34);
22272227 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello"));
22282228}
22292229
......@@ -2247,7 +2247,7 @@ test "integer after float has proper type" {
22472247 \\ "ints": [1, 2, 3]
22482248 \\}
22492249 );
2250 std.testing.expect(json.Object.getValue("ints").?.Array.at(0) == .Integer);
2250 std.testing.expect(json.Object.getValue("ints").?.Array.items[0] == .Integer);
22512251}
22522252
22532253test "escaped characters" {
src-self-hosted/libc_installation.zig+1-1
......@@ -281,7 +281,7 @@ pub const LibCInstallation = struct {
281281 var path_i: usize = 0;
282282 while (path_i < search_paths.items.len) : (path_i += 1) {
283283 // search in reverse order
284 const search_path_untrimmed = search_paths.at(search_paths.items.len - path_i - 1);
284 const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1];
285285 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
286286 var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) {
287287 error.FileNotFound,
test/tests.zig+1-1
......@@ -880,7 +880,7 @@ pub const CompileErrorContext = struct {
880880 var i: usize = 0;
881881 ok = while (err_iter.next()) |line| : (i += 1) {
882882 if (i >= self.case.expected_errors.items.len) break false;
883 const expected = self.case.expected_errors.at(i);
883 const expected = self.case.expected_errors.items[i];
884884 if (mem.indexOf(u8, line, expected) == null) break false;
885885 continue;
886886 } else true;