Skip to content

Commit

Permalink
Fix non-mutated vars
Browse files Browse the repository at this point in the history
  • Loading branch information
natecraddock committed Dec 15, 2023
1 parent a1f1fb9 commit 83f60a4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Previewer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn init(allocator: Allocator, loop: *Loop, cmd: []const u8, arg: []const u8)
const shell = process.getEnvVarOwned(allocator, "SHELL") catch "/bin/sh";

var iter = std.mem.tokenizeSequence(u8, cmd, "{}");
var cmd_parts = [2][]const u8{
const cmd_parts = [2][]const u8{
iter.next() orelse cmd,
iter.next() orelse "",
};
Expand Down
2 changes: 1 addition & 1 deletion src/clib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export fn highlightToken(
const string = std.mem.span(str);
const name = if (filename != null) std.mem.span(filename) else null;
const tok = std.mem.span(token);
var matches_slice = matches[0..matches_len];
const matches_slice = matches[0..matches_len];
const matched = filter.highlightToken(string, name, tok, case_sensitive, strict_path, matches_slice);
return matched.len;
}
Expand Down
8 changes: 4 additions & 4 deletions src/filter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn collectCandidates(allocator: std.mem.Allocator, buf: []const u8, delimite
}

test "collectCandidates whitespace" {
var candidates = try collectCandidates(testing.allocator, "first second third fourth", ' ');
const candidates = try collectCandidates(testing.allocator, "first second third fourth", ' ');
defer testing.allocator.free(candidates);

try testing.expectEqual(@as(usize, 4), candidates.len);
Expand All @@ -47,7 +47,7 @@ test "collectCandidates whitespace" {
}

test "collectCandidates newline" {
var candidates = try collectCandidates(testing.allocator, "first\nsecond\nthird\nfourth", '\n');
const candidates = try collectCandidates(testing.allocator, "first\nsecond\nthird\nfourth", '\n');
defer testing.allocator.free(candidates);

try testing.expectEqual(@as(usize, 4), candidates.len);
Expand All @@ -58,7 +58,7 @@ test "collectCandidates newline" {
}

test "collectCandidates excess whitespace" {
var candidates = try collectCandidates(testing.allocator, " first second third fourth ", ' ');
const candidates = try collectCandidates(testing.allocator, " first second third fourth ", ' ');
defer testing.allocator.free(candidates);

try testing.expectEqual(@as(usize, 4), candidates.len);
Expand Down Expand Up @@ -612,7 +612,7 @@ fn testRankCandidates(
candidates: []const []const u8,
expected: []const []const u8,
) !void {
var ranked_buf = try testing.allocator.alloc(Candidate, candidates.len);
const ranked_buf = try testing.allocator.alloc(Candidate, candidates.len);
defer testing.allocator.free(ranked_buf);
const ranked = rankCandidates(ranked_buf, candidates, tokens, false, false, false);

Expand Down
8 changes: 4 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ pub fn main() anyerror!void {
}
};

var candidates = try filter.collectCandidates(allocator, buf, delimiter);
const candidates = try filter.collectCandidates(allocator, buf, delimiter);
if (candidates.len == 0) std.process.exit(1);

if (config.filter) |query| {
// Use the heap here rather than an array on the stack. Testing showed that this is actually
// faster, likely due to locality with other heap-alloced data used in the algorithm.
var tokens_buf = try allocator.alloc([]const u8, 16);
const tokens_buf = try allocator.alloc([]const u8, 16);
const tokens = ui.splitQuery(tokens_buf, query);
const case_sensitive = ui.hasUpper(query);
var filtered_buf = try allocator.alloc(filter.Candidate, candidates.len);
const filtered_buf = try allocator.alloc(filter.Candidate, candidates.len);
const filtered = filter.rankCandidates(filtered_buf, candidates, tokens, config.keep_order, config.plain, case_sensitive);
if (filtered.len == 0) std.process.exit(1);
for (filtered) |candidate| {
Expand All @@ -82,7 +82,7 @@ pub fn main() anyerror!void {
} else |_| .cyan;

var terminal = try Terminal.init(highlight_color, no_color);
var selected = ui.run(
const selected = ui.run(
allocator,
&terminal,
normalizer,
Expand Down
2 changes: 1 addition & 1 deletion src/term.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const Terminal = struct {
var tty = try std.fs.openFileAbsolute("/dev/tty", .{ .mode = .read_write });

// store original terminal settings to restore later
var termios = try std.os.tcgetattr(tty.handle);
const termios = try std.os.tcgetattr(tty.handle);
var raw_termios = termios;

raw_termios.iflag &= ~@as(u32, c.ICRNL);
Expand Down
4 changes: 2 additions & 2 deletions src/ui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ pub fn run(
}
break :blk try filtered.toOwnedSlice();
};
var filtered_buf = try allocator.alloc(Candidate, candidates.len);
const filtered_buf = try allocator.alloc(Candidate, candidates.len);

var state = State{
.max_height = height,
Expand All @@ -393,7 +393,7 @@ pub fn run(
.query = EditBuffer.init(allocator),
};

var tokens_buf = try allocator.alloc([]const u8, 16);
const tokens_buf = try allocator.alloc([]const u8, 16);
var tokens = splitQuery(tokens_buf, state.query.slice());

var loop = try Loop.init(terminal.tty.handle);
Expand Down

0 comments on commit 83f60a4

Please sign in to comment.