diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index bff88d605a18cf253fc29d577e3d9349789847c3..869471d4e921856cee4fd870c299a95aa0fd5965 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -2666,7 +2666,7 @@ fn makeStep( maker.available_rss += max_rss; dispatch_set.ensureUnusedCapacity(gpa, maker.memory_blocked_steps.items.len) catch @panic("TODO eliminate memory allocation here"); - while (maker.memory_blocked_steps.getLast()) |candidate_index| { + while (maker.memory_blocked_steps.last()) |candidate_index| { const candidate_max_rss = candidate_index.ptr(c).max_rss.toBytes(); if (maker.available_rss < candidate_max_rss) break; assert(maker.memory_blocked_steps.pop() == candidate_index); diff --git a/lib/compiler/translate-c/MacroTranslator.zig b/lib/compiler/translate-c/MacroTranslator.zig index ed4cb8a997a0d87b1bc25d63a1a0f86b6501a313..04b0e9cb3d84a0d78566470e94a7f1ca565ec8b5 100644 --- a/lib/compiler/translate-c/MacroTranslator.zig +++ b/lib/compiler/translate-c/MacroTranslator.zig @@ -361,7 +361,7 @@ fn parseCNumLit(mt: *MacroTranslator) ParseError!ZigNode { return error.ParseError; }, }); - if (bytes.getLast().? == '.') { + if (bytes.last().? == '.') { bytes.appendAssumeCapacity('0'); } else if (mem.findAny(u8, bytes.items, ".eEpP") == null) { bytes.appendSliceAssumeCapacity(".0"); diff --git a/lib/docs/wasm/markdown/Parser.zig b/lib/docs/wasm/markdown/Parser.zig index 3721b11b373b560de6617a4905b56fa106ae6d8e..1bded7541327d17d35aef311c231d6b7171df4e5 100644 --- a/lib/docs/wasm/markdown/Parser.zig +++ b/lib/docs/wasm/markdown/Parser.zig @@ -209,7 +209,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { } else p.pending_blocks.items.len; const in_code_block = p.pending_blocks.items.len > 0 and - p.pending_blocks.getLast().?.tag == .code_block; + p.pending_blocks.last().?.tag == .code_block; const code_block_end = in_code_block and first_unmatched + 1 == p.pending_blocks.items.len; // New blocks cannot be started if we are actively inside a code block or @@ -225,7 +225,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { if (maybe_block_start == null and !isBlank(rest_line) and p.pending_blocks.items.len > 0 and - p.pending_blocks.getLast().?.tag == .paragraph) + p.pending_blocks.last().?.tag == .paragraph) { try p.addScratchStringLine(mem.trimStart(u8, rest_line, " \t")); return; @@ -236,7 +236,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { // paragraphs. if (maybe_block_start != null and p.pending_blocks.items.len > 0 and - p.pending_blocks.getLast().?.tag == .paragraph) + p.pending_blocks.last().?.tag == .paragraph) { try p.closeLastBlock(); } @@ -259,7 +259,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { // Do not append the end of a code block (```) as textual content. if (code_block_end) return; - const can_accept = if (p.pending_blocks.getLast()) |last_pending_block| + const can_accept = if (p.pending_blocks.last()) |last_pending_block| last_pending_block.canAccept() else .blocks; @@ -273,7 +273,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { // loose, since we might just be looking at a blank line after the // end of the last item in the list. The final determination will be // made when appending the next child of the list or list item. - const maybe_containing_list_index = if (p.pending_blocks.items.len > 0 and p.pending_blocks.getLast().?.tag == .list_item) + const maybe_containing_list_index = if (p.pending_blocks.items.len > 0 and p.pending_blocks.last().?.tag == .list_item) p.pending_blocks.items.len - 2 else null; @@ -368,7 +368,7 @@ const BlockStart = struct { }; fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { - if (p.pending_blocks.getLast()) |last_pending_block| { + if (p.pending_blocks.last()) |last_pending_block| { // Close the last block if it is a list and the new block is not a list item // or not of the same marker type. const should_close_list = last_pending_block.tag == .list and @@ -383,7 +383,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { } } - if (p.pending_blocks.getLast()) |last_pending_block| { + if (p.pending_blocks.last()) |last_pending_block| { // If the last block is a list or list item, check for tightness based // on the last line. const maybe_containing_list = switch (last_pending_block.tag) { @@ -401,7 +401,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { // Start a new list if the new block is a list item and there is no // containing list yet. if (block_start.tag == .list_item and - (p.pending_blocks.items.len == 0 or p.pending_blocks.getLast().?.tag != .list)) + (p.pending_blocks.items.len == 0 or p.pending_blocks.last().?.tag != .list)) { try p.pending_blocks.append(p.allocator, .{ .tag = .list, @@ -417,7 +417,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { if (block_start.tag == .table_row) { // Likewise, table rows start a table implicitly. - if (p.pending_blocks.items.len == 0 or p.pending_blocks.getLast().?.tag != .table) { + if (p.pending_blocks.items.len == 0 or p.pending_blocks.last().?.tag != .table) { try p.pending_blocks.append(p.allocator, .{ .tag = .table, .data = .{ .table = .{ @@ -429,7 +429,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { }); } - const current_row = p.scratch_extra.items.len - p.pending_blocks.getLast().?.extra_start; + const current_row = p.scratch_extra.items.len - p.pending_blocks.last().?.extra_start; if (current_row <= 1) { var buffer: [max_table_columns]Node.TableCellAlignment = undefined; const table_row = &block_start.data.table_row; @@ -441,7 +441,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { // We need to go back and mark the header row and its column // alignments. const datas = p.nodes.items(.data); - const header_data = datas[p.scratch_extra.getLast().?]; + const header_data = datas[p.scratch_extra.last().?]; for (p.extraChildren(header_data.container.children), 0..) |header_cell, i| { const alignment = if (i < alignments.len) alignments[i] else .unset; const cell_data = &datas[@backingInt(header_cell)].table_cell; diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index edece7882eaa79caf502cd493833e902b064856d..23a9573a3fa4a05aadd61516ea0f45eeb2212903 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -544,14 +544,22 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type return self.allocatedSlice()[self.items.len..]; } - /// Deprecated in favor of `getLast` - pub const getLastOrNull = getLast; + /// Deprecated in favor of `last` + pub const getLastOrNull = last; - /// Returns the last element from the list, or `null` if the list is empty. - pub fn getLast(self: Self) ?T { + /// Returns the last element from the list, or `null` if the list is + /// empty. + pub fn last(self: Self) ?T { if (self.items.len == 0) return null; return self.items[self.items.len - 1]; } + + /// Returns a pointer to the last element from the list, or `null` if + /// the list is empty. + pub fn lastPtr(self: Self) ?*T { + if (self.items.len == 0) return null; + return &self.items[self.items.len - 1]; + } }; } @@ -1391,15 +1399,16 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { return self.allocatedSlice()[self.items.len..]; } - /// Deprecated in favor of `last`. - pub fn getLast(self: Self) ?T { + /// Returns the last element from the list, or `null` if the list is + /// empty. + pub fn last(self: Self) ?T { if (self.items.len == 0) return null; return self.items[self.items.len - 1]; } /// Returns a pointer to the last element from the list, or `null` if /// the list is empty. - pub fn last(self: Self) ?*T { + pub fn lastPtr(self: Self) ?*T { if (self.items.len == 0) return null; return &self.items[self.items.len - 1]; } @@ -2398,7 +2407,7 @@ test "last" { try testing.expectEqual(list.last(), null); try list.append(a, 2); - try testing.expectEqual(list.last().?.*, 2); + try testing.expectEqual(list.last().?, 2); } test "return OutOfMemory when capacity would exceed maximum usize integer value" { diff --git a/lib/std/deque.zig b/lib/std/deque.zig index c21e1b86567f9f84b9e7078fb751f178b193e5e9..ec40c9d1dbc9eb4b20a3025d22508a90d0a2acec 100644 --- a/lib/std/deque.zig +++ b/lib/std/deque.zig @@ -696,7 +696,7 @@ fn fuzzAgainstArrayList(_: void, smith: *std.testing.Smith) anyerror!void { try q.ensureTotalCapacityPrecise(q_gpa, q.len + growth); }, } - try testing.expectEqual(l.getLast(), q.back()); + try testing.expectEqual(l.last(), q.back()); try testing.expectEqual( if (l.items.len > 0) l.items[0] else null, q.front(), diff --git a/lib/std/zig/Ast/Render.zig b/lib/std/zig/Ast/Render.zig index ddbaea460f5f37dd9885bf00db51c1d62d827ff2..605f3752a78e8908539d294300f3f0a1047b2315 100644 --- a/lib/std/zig/Ast/Render.zig +++ b/lib/std/zig/Ast/Render.zig @@ -3459,7 +3459,7 @@ const AutoIndentingStream = struct { /// Sets current indentation level to be the same as that of the last pushSpace. pub fn enableSpaceMode(ais: *AutoIndentingStream, space: Space) void { if (ais.space_stack.items.len == 0) return; - const curr = ais.space_stack.getLast().?; + const curr = ais.space_stack.last().?; if (curr.space != space) return; ais.space_mode = curr.indent_count; } @@ -3470,7 +3470,7 @@ const AutoIndentingStream = struct { pub fn lastSpaceModeIndent(ais: *AutoIndentingStream) usize { if (ais.space_stack.items.len == 0) return 0; - return ais.space_stack.getLast().?.indent_count * ais.indent_delta; + return ais.space_stack.last().?.indent_count * ais.indent_delta; } /// Push default indentation diff --git a/lib/std/zig/WindowsSdk.zig b/lib/std/zig/WindowsSdk.zig index cddeecbe633eb049abbf014caf49ee38fcfe0ce6..6b8afafd0892561e449f5bd6e40ca46d06d16cce 100644 --- a/lib/std/zig/WindowsSdk.zig +++ b/lib/std/zig/WindowsSdk.zig @@ -891,7 +891,7 @@ const MsvcLibDir = struct { lib_dir_buf.appendSliceAssumeCapacity(installation_path); - if (!Dir.path.isSep(lib_dir_buf.getLast().?)) { + if (!Dir.path.isSep(lib_dir_buf.last().?)) { try lib_dir_buf.append('\\'); } const installation_path_with_trailing_sep_len = lib_dir_buf.items.len; @@ -1064,7 +1064,7 @@ const MsvcLibDir = struct { errdefer msvc_dir.deinit(); // String might contain trailing slash, so trim it here - if (msvc_dir.items.len > "C:\\".len and msvc_dir.getLast().? == '\\') _ = msvc_dir.pop(); + if (msvc_dir.items.len > "C:\\".len and msvc_dir.last().? == '\\') _ = msvc_dir.pop(); // Remove `\include` at the end of path if (std.mem.endsWith(u8, msvc_dir.items, "\\include")) { @@ -1108,7 +1108,7 @@ const MsvcLibDir = struct { try list.appendSlice(VS140COMNTOOLS); // C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools // String might contain trailing slash, so trim it here - if (list.items.len > "C:\\".len and list.getLast().? == '\\') _ = list.pop(); + if (list.items.len > "C:\\".len and list.last().? == '\\') _ = list.pop(); list.shrinkRetainingCapacity(list.items.len - "\\Common7\\Tools".len); // C:\Program Files (x86)\Microsoft Visual Studio 14.0 break :base_path list; } @@ -1131,7 +1131,7 @@ const MsvcLibDir = struct { errdefer path.deinit(); // String might contain trailing slash, so trim it here - if (path.items.len > "C:\\".len and path.getLast().? == '\\') _ = path.pop(); + if (path.items.len > "C:\\".len and path.last().? == '\\') _ = path.pop(); break :base_path path; } return error.PathNotFound; diff --git a/lib/std/zig/llvm/Builder.zig b/lib/std/zig/llvm/Builder.zig index 890ead68aa27a8c0f7f6cd75b97c822f1e8e77c0..8376a569c45ac7191272eabbd0cb84b73b1843db 100644 --- a/lib/std/zig/llvm/Builder.zig +++ b/lib/std/zig/llvm/Builder.zig @@ -2962,7 +2962,7 @@ pub fn trailingStrtabString(self: *Builder) Allocator.Error!StrtabString { } pub fn trailingStrtabStringAssumeCapacity(self: *Builder) StrtabString { - const start = self.strtab_string_indices.getLast().?; + const start = self.strtab_string_indices.last().?; const bytes: []const u8 = self.strtab_string_bytes.items[start..]; const gop = self.strtab_string_map.getOrPutAssumeCapacityAdapted(bytes, StrtabString.Adapter{ .builder = self }); if (gop.found_existing) { @@ -9765,7 +9765,7 @@ pub fn deinit(self: *Builder) void { pub fn finishModuleAsm(self: *Builder, aw: *Writer.Allocating) Allocator.Error!void { self.module_asm = aw.toArrayList(); - if (self.module_asm.getLast()) |last| if (last != '\n') + if (self.module_asm.last()) |last| if (last != '\n') try self.module_asm.append(self.gpa, '\n'); } @@ -9811,7 +9811,7 @@ pub fn trailingString(self: *Builder) Allocator.Error!String { } pub fn trailingStringAssumeCapacity(self: *Builder) String { - const start = self.string_indices.getLast().?; + const start = self.string_indices.last().?; const bytes: []const u8 = self.string_bytes.items[start..]; const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self }); if (gop.found_existing) { @@ -13042,7 +13042,7 @@ pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String { } pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String { - const start = self.metadata_string_indices.getLast().?; + const start = self.metadata_string_indices.last().?; const bytes: []const u8 = self.metadata_string_bytes.items[start..]; assert(bytes.len > 0); const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, Metadata.String.Adapter{ .builder = self }); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 05c329f5d7a1b55b3c0f333ee0985695be364333..2f73d371ea2ed35e82d6923c917581e89ae708c1 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -618,7 +618,7 @@ pub const Object = struct { b.module_asm.appendSliceAssumeCapacity(assembly); b.module_asm.appendAssumeCapacity('\n'); } - if (b.module_asm.getLast()) |last| { + if (b.module_asm.last()) |last| { if (last != '\n') try b.module_asm.append(gpa, '\n'); } } diff --git a/src/codegen/spirv/CodeGen.zig b/src/codegen/spirv/CodeGen.zig index 7833c787e039be9d0002886293000ed5424203f6..1b46cfbbc1fcb105d85bdb6a0bf7b05a480cbcea 100644 --- a/src/codegen/spirv/CodeGen.zig +++ b/src/codegen/spirv/CodeGen.zig @@ -7280,7 +7280,7 @@ fn structuredBreak(cg: *CodeGen, target_block: Id) !void { if (cg.block_terminated) return; const gpa = cg.gpa; - const sblock = cg.block_stack.getLast().?; + const sblock = cg.block_stack.last().?; const merge_block = switch (sblock.*) { .selection => |*merge| blk: { const merge_label = cg.allocId(); @@ -7447,7 +7447,7 @@ fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, body: []const Air.Inst.Index) .operand_2 = this_block, }); - const sblock = cg.block_stack.getLast().?; + const sblock = cg.block_stack.last().?; if (ty.isNoReturn(zcu)) { // If this block is noreturn, this instruction is the last of a block, diff --git a/src/codegen/x86_64/CodeGen.zig b/src/codegen/x86_64/CodeGen.zig index 095de8590a768c68a010bb375f07cf0206c83a10..9a087ca03e284f1bf751c52f77ef393a1c1c5896 100644 --- a/src/codegen/x86_64/CodeGen.zig +++ b/src/codegen/x86_64/CodeGen.zig @@ -2152,7 +2152,7 @@ fn gen( const epilogue = if (self.epilogue_relocs.items.len > 0) epilogue: { var last_inst: Mir.Inst.Index = @intCast(self.mir_instructions.len - 1); - while (self.epilogue_relocs.getLast() == last_inst) { + while (self.epilogue_relocs.last() == last_inst) { self.epilogue_relocs.items.len -= 1; self.mir_instructions.set(last_inst, .{ .tag = .pseudo, @@ -176978,7 +176978,7 @@ fn lowerBlock(self: *CodeGen, inst: Air.Inst.Index, body: []const Air.Inst.Index defer block_data.value.deinit(self.gpa); if (block_data.value.relocs.items.len > 0) { var last_inst: Mir.Inst.Index = @intCast(self.mir_instructions.len - 1); - while (block_data.value.relocs.getLast() == last_inst) { + while (block_data.value.relocs.last() == last_inst) { block_data.value.relocs.items.len -= 1; self.mir_instructions.set(last_inst, .{ .tag = .pseudo, diff --git a/tools/bsp.zig b/tools/bsp.zig index bab0bc2c70afb95e99eb51ccf29be357ce4a678f..b86e30c3af07b53b352602e5b480c0d785055830 100644 --- a/tools/bsp.zig +++ b/tools/bsp.zig @@ -21,7 +21,7 @@ pub fn main(init: std.process.Init) !void { } if (maker_args.items.len < 1) try maker_args.append(arena, "zig"); if (maker_args.items.len < 2) try maker_args.append(arena, "build"); - if (!std.mem.eql(u8, maker_args.last().?.*, "--listen=-")) try maker_args.append(arena, "--listen=-"); + if (!std.mem.eql(u8, maker_args.last().?, "--listen=-")) try maker_args.append(arena, "--listen=-"); log.debug("cmd: {f}", .{std.zig.SubprocessCommand{ .argv = maker_args.items,