| author | |
| committer | |
| log | dbc00e24247da16ac584bb9e92b5ccf04647c3b9 |
| tree | a73219b06cb0ead18b93289975257f2f498f5dd4 |
| parent | 3c34c313cf999238753b34f01b0437a552fb3be0 |
7 files changed, 29 insertions(+), 97 deletions(-)
build.zig+4-4| ... | @@ -136,14 +136,14 @@ pub fn build(b: *Builder) !void { | ... | @@ -136,14 +136,14 @@ pub fn build(b: *Builder) !void { |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { | 138 | fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { |
| 139 | for (dep.libdirs.toSliceConst()) |lib_dir| { | 139 | for (dep.libdirs.items) |lib_dir| { |
| 140 | lib_exe_obj.addLibPath(lib_dir); | 140 | lib_exe_obj.addLibPath(lib_dir); |
| 141 | } | 141 | } |
| 142 | const lib_dir = fs.path.join( | 142 | const lib_dir = fs.path.join( |
| 143 | b.allocator, | 143 | b.allocator, |
| 144 | &[_][]const u8{ dep.prefix, "lib" }, | 144 | &[_][]const u8{ dep.prefix, "lib" }, |
| 145 | ) catch unreachable; | 145 | ) catch unreachable; |
| 146 | for (dep.system_libs.toSliceConst()) |lib| { | 146 | for (dep.system_libs.items) |lib| { |
| 147 | const static_bare_name = if (mem.eql(u8, lib, "curses")) | 147 | const static_bare_name = if (mem.eql(u8, lib, "curses")) |
| 148 | @as([]const u8, "libncurses.a") | 148 | @as([]const u8, "libncurses.a") |
| 149 | else | 149 | else |
| ... | @@ -159,10 +159,10 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { | ... | @@ -159,10 +159,10 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { |
| 159 | lib_exe_obj.linkSystemLibrary(lib); | 159 | lib_exe_obj.linkSystemLibrary(lib); |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | for (dep.libs.toSliceConst()) |lib| { | 162 | for (dep.libs.items) |lib| { |
| 163 | lib_exe_obj.addObjectFile(lib); | 163 | lib_exe_obj.addObjectFile(lib); |
| 164 | } | 164 | } |
| 165 | for (dep.includes.toSliceConst()) |include_path| { | 165 | for (dep.includes.items) |include_path| { |
| 166 | lib_exe_obj.addIncludeDir(include_path); | 166 | lib_exe_obj.addIncludeDir(include_path); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
lib/std/array_list.zig+9-77| ... | @@ -57,37 +57,13 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -57,37 +57,13 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { |
| 57 | return self.items; | 57 | return self.items; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /// Deprecated: use `items` field directly. | 60 | pub const toSlice = @compileError("deprecated: use `items` field directly"); |
| 61 | pub fn toSlice(self: Self) Slice { | 61 | pub const toSliceConst = @compileError("deprecated: use `items` field directly"); |
| 62 | return self.items; | 62 | pub const at = @compileError("deprecated: use `list.items[i]`"); |
| 63 | } | 63 | pub const ptrAt = @compileError("deprecated: use `&list.items[i]`"); |
| 64 | 64 | pub const setOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`"); | |
| 65 | /// Deprecated: use `items` field directly. | 65 | pub const set = @compileError("deprecated: use `list.items[i] = item`"); |
| 66 | pub fn toSliceConst(self: Self) SliceConst { | 66 | pub const swapRemoveOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`"); |
| 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 | } | ||
| 91 | 67 | ||
| 92 | /// ArrayList takes ownership of the passed in slice. The slice must have been | 68 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 93 | /// allocated with `allocator`. | 69 | /// allocated with `allocator`. |
| ... | @@ -167,12 +143,6 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -167,12 +143,6 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { |
| 167 | return old_item; | 143 | return old_item; |
| 168 | } | 144 | } |
| 169 | 145 | ||
| 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 | |||
| 176 | /// Append the slice of items to the list. Allocates more | 146 | /// Append the slice of items to the list. Allocates more |
| 177 | /// memory as necessary. | 147 | /// memory as necessary. |
| 178 | pub fn appendSlice(self: *Self, items: SliceConst) !void { | 148 | pub fn appendSlice(self: *Self, items: SliceConst) !void { |
| ... | @@ -308,9 +278,6 @@ test "std.ArrayList.basic" { | ... | @@ -308,9 +278,6 @@ test "std.ArrayList.basic" { |
| 308 | var list = ArrayList(i32).init(testing.allocator); | 278 | var list = ArrayList(i32).init(testing.allocator); |
| 309 | defer list.deinit(); | 279 | defer list.deinit(); |
| 310 | 280 | ||
| 311 | // setting on empty list is out of bounds | ||
| 312 | testing.expectError(error.OutOfBounds, list.setOrError(0, 1)); | ||
| 313 | |||
| 314 | { | 281 | { |
| 315 | var i: usize = 0; | 282 | var i: usize = 0; |
| 316 | while (i < 10) : (i += 1) { | 283 | while (i < 10) : (i += 1) { |
| ... | @@ -329,10 +296,6 @@ test "std.ArrayList.basic" { | ... | @@ -329,10 +296,6 @@ test "std.ArrayList.basic" { |
| 329 | testing.expect(v == @intCast(i32, i + 1)); | 296 | testing.expect(v == @intCast(i32, i + 1)); |
| 330 | } | 297 | } |
| 331 | 298 | ||
| 332 | for (list.toSliceConst()) |v, i| { | ||
| 333 | testing.expect(v == @intCast(i32, i + 1)); | ||
| 334 | } | ||
| 335 | |||
| 336 | testing.expect(list.pop() == 10); | 299 | testing.expect(list.pop() == 10); |
| 337 | testing.expect(list.items.len == 9); | 300 | testing.expect(list.items.len == 9); |
| 338 | 301 | ||
| ... | @@ -347,11 +310,8 @@ test "std.ArrayList.basic" { | ... | @@ -347,11 +310,8 @@ test "std.ArrayList.basic" { |
| 347 | testing.expect(list.items.len == 9); | 310 | testing.expect(list.items.len == 9); |
| 348 | 311 | ||
| 349 | // can only set on indices < self.items.len | 312 | // can only set on indices < self.items.len |
| 350 | list.set(7, 33); | 313 | list.items[7] = 33; |
| 351 | list.set(8, 42); | 314 | list.items[8] = 42; |
| 352 | |||
| 353 | testing.expectError(error.OutOfBounds, list.setOrError(9, 99)); | ||
| 354 | testing.expectError(error.OutOfBounds, list.setOrError(10, 123)); | ||
| 355 | 315 | ||
| 356 | testing.expect(list.pop() == 42); | 316 | testing.expect(list.pop() == 42); |
| 357 | testing.expect(list.pop() == 33); | 317 | testing.expect(list.pop() == 33); |
| ... | @@ -428,34 +388,6 @@ test "std.ArrayList.swapRemove" { | ... | @@ -428,34 +388,6 @@ test "std.ArrayList.swapRemove" { |
| 428 | testing.expect(list.items.len == 4); | 388 | testing.expect(list.items.len == 4); |
| 429 | } | 389 | } |
| 430 | 390 | ||
| 431 | test "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 | |||
| 459 | test "std.ArrayList.insert" { | 391 | test "std.ArrayList.insert" { |
| 460 | var list = ArrayList(i32).init(testing.allocator); | 392 | var list = ArrayList(i32).init(testing.allocator); |
| 461 | defer list.deinit(); | 393 | defer list.deinit(); |
lib/std/fs/test.zig+1-1| ... | @@ -158,7 +158,7 @@ const FileLockTestContext = struct { | ... | @@ -158,7 +158,7 @@ const FileLockTestContext = struct { |
| 158 | fn run_lock_file_test(contexts: []FileLockTestContext) !void { | 158 | fn run_lock_file_test(contexts: []FileLockTestContext) !void { |
| 159 | var threads = std.ArrayList(*std.Thread).init(std.testing.allocator); | 159 | var threads = std.ArrayList(*std.Thread).init(std.testing.allocator); |
| 160 | defer { | 160 | defer { |
| 161 | for (threads.toSlice()) |thread| { | 161 | for (threads.items) |thread| { |
| 162 | thread.wait(); | 162 | thread.wait(); |
| 163 | } | 163 | } |
| 164 | threads.deinit(); | 164 | threads.deinit(); |
lib/std/http/headers.zig+8-8| ... | @@ -200,7 +200,7 @@ pub const Headers = struct { | ... | @@ -200,7 +200,7 @@ pub const Headers = struct { |
| 200 | var i = dex.items.len; | 200 | var i = dex.items.len; |
| 201 | while (i > 0) { | 201 | while (i > 0) { |
| 202 | i -= 1; | 202 | i -= 1; |
| 203 | const data_index = dex.at(i); | 203 | const data_index = dex.items[i]; |
| 204 | const removed = self.data.orderedRemove(data_index); | 204 | const removed = self.data.orderedRemove(data_index); |
| 205 | assert(mem.eql(u8, removed.name, name)); | 205 | assert(mem.eql(u8, removed.name, name)); |
| 206 | removed.deinit(); | 206 | removed.deinit(); |
| ... | @@ -260,7 +260,7 @@ pub const Headers = struct { | ... | @@ -260,7 +260,7 @@ pub const Headers = struct { |
| 260 | 260 | ||
| 261 | /// Access the header at the specified index. | 261 | /// Access the header at the specified index. |
| 262 | pub fn at(self: Self, i: usize) HeaderEntry { | 262 | pub fn at(self: Self, i: usize) HeaderEntry { |
| 263 | return self.data.at(i); | 263 | return self.data.items[i]; |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | /// Returns a list of indices containing headers with the given name. | 266 | /// Returns a list of indices containing headers with the given name. |
| ... | @@ -280,7 +280,7 @@ pub const Headers = struct { | ... | @@ -280,7 +280,7 @@ pub const Headers = struct { |
| 280 | const buf = try allocator.alloc(HeaderEntry, dex.items.len); | 280 | const buf = try allocator.alloc(HeaderEntry, dex.items.len); |
| 281 | var n: usize = 0; | 281 | var n: usize = 0; |
| 282 | for (dex.span()) |idx| { | 282 | for (dex.span()) |idx| { |
| 283 | buf[n] = self.data.at(idx); | 283 | buf[n] = self.data.items[idx]; |
| 284 | n += 1; | 284 | n += 1; |
| 285 | } | 285 | } |
| 286 | return buf; | 286 | return buf; |
| ... | @@ -303,18 +303,18 @@ pub const Headers = struct { | ... | @@ -303,18 +303,18 @@ pub const Headers = struct { |
| 303 | const total_len = blk: { | 303 | const total_len = blk: { |
| 304 | var sum: usize = dex.items.len - 1; // space for separator(s) | 304 | var sum: usize = dex.items.len - 1; // space for separator(s) |
| 305 | for (dex.span()) |idx| | 305 | for (dex.span()) |idx| |
| 306 | sum += self.data.at(idx).value.len; | 306 | sum += self.data.items[idx].value.len; |
| 307 | break :blk sum; | 307 | break :blk sum; |
| 308 | }; | 308 | }; |
| 309 | 309 | ||
| 310 | const buf = try allocator.alloc(u8, total_len); | 310 | const buf = try allocator.alloc(u8, total_len); |
| 311 | errdefer allocator.free(buf); | 311 | errdefer allocator.free(buf); |
| 312 | 312 | ||
| 313 | const first_value = self.data.at(dex.at(0)).value; | 313 | const first_value = self.data.items[dex.items[0]].value; |
| 314 | mem.copy(u8, buf, first_value); | 314 | mem.copy(u8, buf, first_value); |
| 315 | var buf_index: usize = first_value.len; | 315 | var buf_index: usize = first_value.len; |
| 316 | for (dex.toSlice()[1..]) |idx| { | 316 | for (dex.items[1..]) |idx| { |
| 317 | const value = self.data.at(idx).value; | 317 | const value = self.data.items[idx].value; |
| 318 | buf[buf_index] = ','; | 318 | buf[buf_index] = ','; |
| 319 | buf_index += 1; | 319 | buf_index += 1; |
| 320 | mem.copy(u8, buf[buf_index..], value); | 320 | mem.copy(u8, buf[buf_index..], value); |
| ... | @@ -342,7 +342,7 @@ pub const Headers = struct { | ... | @@ -342,7 +342,7 @@ pub const Headers = struct { |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | pub fn sort(self: *Self) void { | 344 | 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); |
| 346 | self.rebuild_index(); | 346 | self.rebuild_index(); |
| 347 | } | 347 | } |
| 348 | 348 |
lib/std/json.zig+5-5| ... | @@ -1879,7 +1879,7 @@ pub const Parser = struct { | ... | @@ -1879,7 +1879,7 @@ pub const Parser = struct { |
| 1879 | 1879 | ||
| 1880 | return ValueTree{ | 1880 | return ValueTree{ |
| 1881 | .arena = arena, | 1881 | .arena = arena, |
| 1882 | .root = p.stack.at(0), | 1882 | .root = p.stack.items[0], |
| 1883 | }; | 1883 | }; |
| 1884 | } | 1884 | } |
| 1885 | 1885 | ||
| ... | @@ -2168,7 +2168,7 @@ test "json.parser.dynamic" { | ... | @@ -2168,7 +2168,7 @@ test "json.parser.dynamic" { |
| 2168 | const array_of_object = image.Object.get("ArrayOfObject").?.value; | 2168 | const array_of_object = image.Object.get("ArrayOfObject").?.value; |
| 2169 | testing.expect(array_of_object.Array.items.len == 1); | 2169 | testing.expect(array_of_object.Array.items.len == 1); |
| 2170 | 2170 | ||
| 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; |
| 2172 | testing.expect(mem.eql(u8, obj0.String, "m")); | 2172 | testing.expect(mem.eql(u8, obj0.String, "m")); |
| 2173 | 2173 | ||
| 2174 | const double = image.Object.get("double").?.value; | 2174 | const double = image.Object.get("double").?.value; |
| ... | @@ -2222,8 +2222,8 @@ test "write json then parse it" { | ... | @@ -2222,8 +2222,8 @@ test "write json then parse it" { |
| 2222 | testing.expect(tree.root.Object.get("f").?.value.Bool == false); | 2222 | testing.expect(tree.root.Object.get("f").?.value.Bool == false); |
| 2223 | testing.expect(tree.root.Object.get("t").?.value.Bool == true); | 2223 | testing.expect(tree.root.Object.get("t").?.value.Bool == true); |
| 2224 | testing.expect(tree.root.Object.get("int").?.value.Integer == 1234); | 2224 | testing.expect(tree.root.Object.get("int").?.value.Integer == 1234); |
| 2225 | testing.expect(tree.root.Object.get("array").?.value.Array.at(0).Null == {}); | 2225 | testing.expect(tree.root.Object.get("array").?.value.Array.items[0].Null == {}); |
| 2226 | testing.expect(tree.root.Object.get("array").?.value.Array.at(1).Float == 12.34); | 2226 | testing.expect(tree.root.Object.get("array").?.value.Array.items[1].Float == 12.34); |
| 2227 | testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello")); | 2227 | testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello")); |
| 2228 | } | 2228 | } |
| 2229 | 2229 | ||
| ... | @@ -2247,7 +2247,7 @@ test "integer after float has proper type" { | ... | @@ -2247,7 +2247,7 @@ test "integer after float has proper type" { |
| 2247 | \\ "ints": [1, 2, 3] | 2247 | \\ "ints": [1, 2, 3] |
| 2248 | \\} | 2248 | \\} |
| 2249 | ); | 2249 | ); |
| 2250 | std.testing.expect(json.Object.getValue("ints").?.Array.at(0) == .Integer); | 2250 | std.testing.expect(json.Object.getValue("ints").?.Array.items[0] == .Integer); |
| 2251 | } | 2251 | } |
| 2252 | 2252 | ||
| 2253 | test "escaped characters" { | 2253 | test "escaped characters" { |
src-self-hosted/libc_installation.zig+1-1| ... | @@ -281,7 +281,7 @@ pub const LibCInstallation = struct { | ... | @@ -281,7 +281,7 @@ pub const LibCInstallation = struct { |
| 281 | var path_i: usize = 0; | 281 | var path_i: usize = 0; |
| 282 | while (path_i < search_paths.items.len) : (path_i += 1) { | 282 | while (path_i < search_paths.items.len) : (path_i += 1) { |
| 283 | // search in reverse order | 283 | // 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]; |
| 285 | const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " "); | 285 | const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " "); |
| 286 | var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) { | 286 | var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) { |
| 287 | error.FileNotFound, | 287 | error.FileNotFound, |
test/tests.zig+1-1| ... | @@ -880,7 +880,7 @@ pub const CompileErrorContext = struct { | ... | @@ -880,7 +880,7 @@ pub const CompileErrorContext = struct { |
| 880 | var i: usize = 0; | 880 | var i: usize = 0; |
| 881 | ok = while (err_iter.next()) |line| : (i += 1) { | 881 | ok = while (err_iter.next()) |line| : (i += 1) { |
| 882 | if (i >= self.case.expected_errors.items.len) break false; | 882 | 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]; |
| 884 | if (mem.indexOf(u8, line, expected) == null) break false; | 884 | if (mem.indexOf(u8, line, expected) == null) break false; |
| 885 | continue; | 885 | continue; |
| 886 | } else true; | 886 | } else true; |