update zig, src for loops

This commit is contained in:
Mitchell Hashimoto
2023-02-27 21:46:42 -08:00
parent 82706050d9
commit ce86c64b42
9 changed files with 15 additions and 15 deletions

6
flake.lock generated
View File

@ -126,11 +126,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1676852827, "lastModified": 1677457546,
"narHash": "sha256-PiUegeTKdyvsGVzdrTeoWTXTPNRQ/bhX/3MjKzzERiQ=", "narHash": "sha256-R2k5sOzf6dEg/PbMfZNYFjmJQY1Hbd/4sc8H36I3EAM=",
"owner": "mitchellh", "owner": "mitchellh",
"repo": "zig-overlay", "repo": "zig-overlay",
"rev": "8b3bf31d01b67b79e2f34eb9b6f6d313c8a203ca", "rev": "2b07e4e3e3eb07134ac61049abdc1da1ff6c5516",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -112,7 +112,7 @@ pub fn start(self: *Command, alloc: Allocator) !void {
// Null-terminate all our arguments // Null-terminate all our arguments
const pathZ = try arena.dupeZ(u8, self.path); const pathZ = try arena.dupeZ(u8, self.path);
const argsZ = try arena.allocSentinel(?[*:0]u8, self.args.len, null); const argsZ = try arena.allocSentinel(?[*:0]u8, self.args.len, null);
for (self.args) |arg, i| argsZ[i] = (try arena.dupeZ(u8, arg)).ptr; for (self.args, 0..) |arg, i| argsZ[i] = (try arena.dupeZ(u8, arg)).ptr;
// Determine our env vars // Determine our env vars
const envp = if (self.env) |env_map| const envp = if (self.env) |env_map|

View File

@ -1417,7 +1417,7 @@ pub fn cursorPosCallback(
if (self.io.terminal.modes.mouse_event != .none) { if (self.io.terminal.modes.mouse_event != .none) {
// We use the first mouse button we find pressed in order to report // We use the first mouse button we find pressed in order to report
// since the spec (afaict) does not say... // since the spec (afaict) does not say...
const button: ?input.MouseButton = button: for (self.mouse.click_state) |state, i| { const button: ?input.MouseButton = button: for (self.mouse.click_state, 0..) |state, i| {
if (state == .press) if (state == .press)
break :button @intToEnum(input.MouseButton, i); break :button @intToEnum(input.MouseButton, i);
} else null; } else null;

View File

@ -860,7 +860,7 @@ pub const Surface = struct {
// that assumption is true. // that assumption is true.
const keyval = keyval: { const keyval = keyval: {
if (found > 0) { if (found > 0) {
for (keys[0..@intCast(usize, keys_len)]) |key, i| { for (keys[0..@intCast(usize, keys_len)], 0..) |key, i| {
if (key.group == 0 and key.level == 0) if (key.group == 0 and key.level == 0)
break :keyval keyvals[i]; break :keyval keyvals[i];
} }

View File

@ -404,7 +404,7 @@ pub const Wasm = struct {
var buf: []u8 = try alloc.alloc(u8, self.data.len * 4); var buf: []u8 = try alloc.alloc(u8, self.data.len * 4);
errdefer alloc.free(buf); errdefer alloc.free(buf);
std.mem.set(u8, buf, 0); std.mem.set(u8, buf, 0);
for (self.data) |value, i| { for (self.data, 0..) |value, i| {
buf[(i * 4) + 3] = value; buf[(i * 4) + 3] = value;
} }
break :buf buf; break :buf buf;

View File

@ -219,7 +219,7 @@ pub fn indexForCodepoint(
} }
fn indexForCodepointExact(self: Group, cp: u32, style: Style, p: ?Presentation) ?FontIndex { fn indexForCodepointExact(self: Group, cp: u32, style: Style, p: ?Presentation) ?FontIndex {
for (self.faces.get(style).items) |deferred, i| { for (self.faces.get(style).items, 0..) |deferred, i| {
if (deferred.hasCodepoint(cp, p)) { if (deferred.hasCodepoint(cp, p)) {
return FontIndex{ return FontIndex{
.style = style, .style = style,

View File

@ -89,7 +89,7 @@ pub const Shaper = struct {
if (info.len > self.cell_buf.len) return error.OutOfMemory; if (info.len > self.cell_buf.len) return error.OutOfMemory;
//log.warn("info={} pos={} run={}", .{ info.len, pos.len, run }); //log.warn("info={} pos={} run={}", .{ info.len, pos.len, run });
for (info) |v, i| { for (info, 0..) |v, i| {
self.cell_buf[i] = .{ self.cell_buf[i] = .{
.x = @intCast(u16, v.cluster), .x = @intCast(u16, v.cluster),
.glyph_index = v.codepoint, .glyph_index = v.codepoint,

View File

@ -316,7 +316,7 @@ pub const Row = struct {
} }
// We have graphemes, so we have to clear those first. // We have graphemes, so we have to clear those first.
for (self.storage[start + 1 .. len + 1]) |*storage_cell, x| { for (self.storage[start + 1 .. len + 1], 0..) |*storage_cell, x| {
if (storage_cell.cell.attrs.grapheme) self.clearGraphemes(x); if (storage_cell.cell.attrs.grapheme) self.clearGraphemes(x);
storage_cell.* = .{ .cell = cell }; storage_cell.* = .{ .cell = cell };
} }
@ -413,7 +413,7 @@ pub const Row = struct {
} }
// Source has graphemes, this is slow. // Source has graphemes, this is slow.
for (src.storage[1..end]) |storage, x| { for (src.storage[1..end], 0..) |storage, x| {
self.storage[x + 1] = .{ .cell = storage.cell }; self.storage[x + 1] = .{ .cell = storage.cell };
// Copy grapheme data if it exists // Copy grapheme data if it exists
@ -1056,7 +1056,7 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi
}; };
// Zero // Zero
for (zero_offset) |offset, i| { for (zero_offset, 0..) |offset, i| {
if (offset >= slices[i].len) continue; if (offset >= slices[i].len) continue;
const dst = slices[i][offset..]; const dst = slices[i][offset..];
@ -1488,7 +1488,7 @@ pub fn selectionString(
var count: usize = 0; var count: usize = 0;
const arr = [_][]StorageCell{ slices.top, slices.bot }; const arr = [_][]StorageCell{ slices.top, slices.bot };
for (arr) |slice| { for (arr) |slice| {
for (slice) |cell, i| { for (slice, 0..) |cell, i| {
// detect row headers // detect row headers
if (@mod(i, self.cols + 1) == 0) { if (@mod(i, self.cols + 1) == 0) {
// We use each row header as an opportunity to "count" // We use each row header as an opportunity to "count"
@ -1967,7 +1967,7 @@ pub fn resize(self: *Screen, rows: usize, cols: usize) !void {
}; };
// Copy all the cells into our row. // Copy all the cells into our row.
for (trimmed_row) |cell, i| { for (trimmed_row, 0..) |cell, i| {
// Soft wrap if we have to // Soft wrap if we have to
if (x == self.cols) { if (x == self.cols) {
var row = self.getRow(.{ .active = y }); var row = self.getRow(.{ .active = y });

View File

@ -32,7 +32,7 @@ const prealloc_count = prealloc_columns / unit_bits;
/// We precompute all the possible masks since we never use a huge bit size. /// We precompute all the possible masks since we never use a huge bit size.
const masks = blk: { const masks = blk: {
var res: [unit_bits]Unit = undefined; var res: [unit_bits]Unit = undefined;
for (res) |_, i| { for (res, 0..) |_, i| {
res[i] = @shlExact(@as(Unit, 1), @intCast(u3, i)); res[i] = @shlExact(@as(Unit, 1), @intCast(u3, i));
} }