Skip to content

Commit 61e00fb

Browse files
authored
correct unnecessary uses of 'var' (#16)
1 parent 90353d4 commit 61e00fb

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

DiffMatchPatch.zig

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn diffInternal(
112112

113113
// Trim off common suffix (speedup).
114114
common_length = diffCommonSuffix(trimmed_before, trimmed_after);
115-
var common_suffix = trimmed_before[trimmed_before.len - common_length ..];
115+
const common_suffix = trimmed_before[trimmed_before.len - common_length ..];
116116
trimmed_before = trimmed_before[0 .. trimmed_before.len - common_length];
117117
trimmed_after = trimmed_after[0 .. trimmed_after.len - common_length];
118118

@@ -216,7 +216,7 @@ fn diffCompute(
216216
// A half-match was found, sort out the return data.
217217

218218
// Send both pairs off for separate processing.
219-
var diffs_a = try dmp.diffInternal(
219+
const diffs_a = try dmp.diffInternal(
220220
allocator,
221221
half_match.prefix_before,
222222
half_match.prefix_after,
@@ -283,9 +283,9 @@ fn diffHalfMatch(
283283
}
284284

285285
// First check if the second quarter is the seed for a half-match.
286-
var half_match_1 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 3) / 4);
286+
const half_match_1 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 3) / 4);
287287
// Check again based on the third quarter.
288-
var half_match_2 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 1) / 2);
288+
const half_match_2 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 1) / 2);
289289

290290
var half_match: ?HalfMatchResult = null;
291291
if (half_match_1 == null and half_match_2 == null) {
@@ -346,8 +346,8 @@ fn diffHalfMatchInternal(
346346
j = @as(isize, @intCast(std.mem.indexOf(u8, short_text[@as(usize, @intCast(j + 1))..], seed) orelse break :b false)) + j + 1;
347347
break :b true;
348348
}) {
349-
var prefix_length = diffCommonPrefix(long_text[i..], short_text[@as(usize, @intCast(j))..]);
350-
var suffix_length = diffCommonSuffix(long_text[0..i], short_text[0..@as(usize, @intCast(j))]);
349+
const prefix_length = diffCommonPrefix(long_text[i..], short_text[@as(usize, @intCast(j))..]);
350+
const suffix_length = diffCommonSuffix(long_text[0..i], short_text[0..@as(usize, @intCast(j))]);
351351
if (best_common.items.len < suffix_length + prefix_length) {
352352
best_common.items.len = 0;
353353
try best_common.appendSlice(allocator, short_text[@as(usize, @intCast(j - @as(isize, @intCast(suffix_length)))) .. @as(usize, @intCast(j - @as(isize, @intCast(suffix_length)))) + suffix_length]);
@@ -425,7 +425,7 @@ fn diffBisect(
425425
// Walk the front path one step.
426426
var k1 = -d + k1start;
427427
while (k1 <= d - k1end) : (k1 += 2) {
428-
var k1_offset = v_offset + k1;
428+
const k1_offset = v_offset + k1;
429429
var x1: isize = 0;
430430
if (k1 == -d or (k1 != d and
431431
v1.items[@intCast(k1_offset - 1)] < v1.items[@intCast(k1_offset + 1)]))
@@ -449,7 +449,7 @@ fn diffBisect(
449449
// Ran off the bottom of the graph.
450450
k1start += 2;
451451
} else if (front) {
452-
var k2_offset = v_offset + delta - k1;
452+
const k2_offset = v_offset + delta - k1;
453453
if (k2_offset >= 0 and k2_offset < v_length and v2.items[@intCast(k2_offset)] != -1) {
454454
// Mirror x2 onto top-left coordinate system.
455455
const x2 = before_length - v2.items[@intCast(k2_offset)];
@@ -557,10 +557,10 @@ fn diffLineMode(
557557
deadline: u64,
558558
) DiffError!DiffList {
559559
// Scan the text on a line-by-line basis first.
560-
var a = try diffLinesToChars(allocator, text1_in, text2_in);
561-
var text1 = a.chars_1;
562-
var text2 = a.chars_2;
563-
var line_array = a.line_array;
560+
const a = try diffLinesToChars(allocator, text1_in, text2_in);
561+
const text1 = a.chars_1;
562+
const text2 = a.chars_2;
563+
const line_array = a.line_array;
564564

565565
var diffs: DiffList = try dmp.diffInternal(allocator, text1, text2, false, deadline);
566566

@@ -607,7 +607,7 @@ fn diffLineMode(
607607
&.{},
608608
);
609609
pointer = pointer - count_delete - count_insert;
610-
var sub_diff = try dmp.diffInternal(allocator, text_delete.items, text_insert.items, false, deadline);
610+
const sub_diff = try dmp.diffInternal(allocator, text_delete.items, text_insert.items, false, deadline);
611611
// diffs.InsertRange(pointer, sub_diff);
612612
try diffs.insertSlice(allocator, pointer, sub_diff.items);
613613
pointer = pointer + sub_diff.items.len;
@@ -654,8 +654,8 @@ fn diffLinesToChars(
654654
try line_array.append(allocator, "");
655655

656656
// Allocate 2/3rds of the space for text1, the rest for text2.
657-
var chars1 = try diffLinesToCharsMunge(allocator, text1, &line_array, &line_hash, 170);
658-
var chars2 = try diffLinesToCharsMunge(allocator, text2, &line_array, &line_hash, 255);
657+
const chars1 = try diffLinesToCharsMunge(allocator, text1, &line_array, &line_hash, 170);
658+
const chars2 = try diffLinesToCharsMunge(allocator, text2, &line_array, &line_hash, 255);
659659
return .{ .chars_1 = chars1, .chars_2 = chars2, .line_array = line_array };
660660
}
661661

@@ -997,8 +997,8 @@ fn diffCleanupSemantic(allocator: std.mem.Allocator, diffs: *DiffList) DiffError
997997
{
998998
const deletion = diffs.items[@intCast(pointer - 1)].text;
999999
const insertion = diffs.items[@intCast(pointer)].text;
1000-
var overlap_length1: usize = diffCommonOverlap(deletion, insertion);
1001-
var overlap_length2: usize = diffCommonOverlap(insertion, deletion);
1000+
const overlap_length1: usize = diffCommonOverlap(deletion, insertion);
1001+
const overlap_length2: usize = diffCommonOverlap(insertion, deletion);
10021002
if (overlap_length1 >= overlap_length2) {
10031003
if (@as(f32, @floatFromInt(overlap_length1)) >= @as(f32, @floatFromInt(deletion.len)) / 2.0 or
10041004
@as(f32, @floatFromInt(overlap_length1)) >= @as(f32, @floatFromInt(insertion.len)) / 2.0)
@@ -1314,8 +1314,8 @@ fn diffCommonOverlap(text1_in: []const u8, text2_in: []const u8) usize {
13141314
var text2 = text2_in;
13151315

13161316
// Cache the text lengths to prevent multiple calls.
1317-
var text1_length = text1.len;
1318-
var text2_length = text2.len;
1317+
const text1_length = text1.len;
1318+
const text2_length = text2.len;
13191319
// Eliminate the null case.
13201320
if (text1_length == 0 or text2_length == 0) {
13211321
return 0;

0 commit comments

Comments
 (0)