diff --git a/DiffMatchPatch.zig b/DiffMatchPatch.zig index b4b2a41..1061111 100644 --- a/DiffMatchPatch.zig +++ b/DiffMatchPatch.zig @@ -112,7 +112,7 @@ fn diffInternal( // Trim off common suffix (speedup). common_length = diffCommonSuffix(trimmed_before, trimmed_after); - var common_suffix = trimmed_before[trimmed_before.len - common_length ..]; + const common_suffix = trimmed_before[trimmed_before.len - common_length ..]; trimmed_before = trimmed_before[0 .. trimmed_before.len - common_length]; trimmed_after = trimmed_after[0 .. trimmed_after.len - common_length]; @@ -216,7 +216,7 @@ fn diffCompute( // A half-match was found, sort out the return data. // Send both pairs off for separate processing. - var diffs_a = try dmp.diffInternal( + const diffs_a = try dmp.diffInternal( allocator, half_match.prefix_before, half_match.prefix_after, @@ -283,9 +283,9 @@ fn diffHalfMatch( } // First check if the second quarter is the seed for a half-match. - var half_match_1 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 3) / 4); + const half_match_1 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 3) / 4); // Check again based on the third quarter. - var half_match_2 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 1) / 2); + const half_match_2 = try dmp.diffHalfMatchInternal(allocator, long_text, short_text, (long_text.len + 1) / 2); var half_match: ?HalfMatchResult = null; if (half_match_1 == null and half_match_2 == null) { @@ -346,8 +346,8 @@ fn diffHalfMatchInternal( j = @as(isize, @intCast(std.mem.indexOf(u8, short_text[@as(usize, @intCast(j + 1))..], seed) orelse break :b false)) + j + 1; break :b true; }) { - var prefix_length = diffCommonPrefix(long_text[i..], short_text[@as(usize, @intCast(j))..]); - var suffix_length = diffCommonSuffix(long_text[0..i], short_text[0..@as(usize, @intCast(j))]); + const prefix_length = diffCommonPrefix(long_text[i..], short_text[@as(usize, @intCast(j))..]); + const suffix_length = diffCommonSuffix(long_text[0..i], short_text[0..@as(usize, @intCast(j))]); if (best_common.items.len < suffix_length + prefix_length) { best_common.items.len = 0; 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( // Walk the front path one step. var k1 = -d + k1start; while (k1 <= d - k1end) : (k1 += 2) { - var k1_offset = v_offset + k1; + const k1_offset = v_offset + k1; var x1: isize = 0; if (k1 == -d or (k1 != d and v1.items[@intCast(k1_offset - 1)] < v1.items[@intCast(k1_offset + 1)])) @@ -449,7 +449,7 @@ fn diffBisect( // Ran off the bottom of the graph. k1start += 2; } else if (front) { - var k2_offset = v_offset + delta - k1; + const k2_offset = v_offset + delta - k1; if (k2_offset >= 0 and k2_offset < v_length and v2.items[@intCast(k2_offset)] != -1) { // Mirror x2 onto top-left coordinate system. const x2 = before_length - v2.items[@intCast(k2_offset)]; @@ -557,10 +557,10 @@ fn diffLineMode( deadline: u64, ) DiffError!DiffList { // Scan the text on a line-by-line basis first. - var a = try diffLinesToChars(allocator, text1_in, text2_in); - var text1 = a.chars_1; - var text2 = a.chars_2; - var line_array = a.line_array; + const a = try diffLinesToChars(allocator, text1_in, text2_in); + const text1 = a.chars_1; + const text2 = a.chars_2; + const line_array = a.line_array; var diffs: DiffList = try dmp.diffInternal(allocator, text1, text2, false, deadline); @@ -607,7 +607,7 @@ fn diffLineMode( &.{}, ); pointer = pointer - count_delete - count_insert; - var sub_diff = try dmp.diffInternal(allocator, text_delete.items, text_insert.items, false, deadline); + const sub_diff = try dmp.diffInternal(allocator, text_delete.items, text_insert.items, false, deadline); // diffs.InsertRange(pointer, sub_diff); try diffs.insertSlice(allocator, pointer, sub_diff.items); pointer = pointer + sub_diff.items.len; @@ -654,8 +654,8 @@ fn diffLinesToChars( try line_array.append(allocator, ""); // Allocate 2/3rds of the space for text1, the rest for text2. - var chars1 = try diffLinesToCharsMunge(allocator, text1, &line_array, &line_hash, 170); - var chars2 = try diffLinesToCharsMunge(allocator, text2, &line_array, &line_hash, 255); + const chars1 = try diffLinesToCharsMunge(allocator, text1, &line_array, &line_hash, 170); + const chars2 = try diffLinesToCharsMunge(allocator, text2, &line_array, &line_hash, 255); return .{ .chars_1 = chars1, .chars_2 = chars2, .line_array = line_array }; } @@ -997,8 +997,8 @@ fn diffCleanupSemantic(allocator: std.mem.Allocator, diffs: *DiffList) DiffError { const deletion = diffs.items[@intCast(pointer - 1)].text; const insertion = diffs.items[@intCast(pointer)].text; - var overlap_length1: usize = diffCommonOverlap(deletion, insertion); - var overlap_length2: usize = diffCommonOverlap(insertion, deletion); + const overlap_length1: usize = diffCommonOverlap(deletion, insertion); + const overlap_length2: usize = diffCommonOverlap(insertion, deletion); if (overlap_length1 >= overlap_length2) { if (@as(f32, @floatFromInt(overlap_length1)) >= @as(f32, @floatFromInt(deletion.len)) / 2.0 or @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 { var text2 = text2_in; // Cache the text lengths to prevent multiple calls. - var text1_length = text1.len; - var text2_length = text2.len; + const text1_length = text1.len; + const text2_length = text2.len; // Eliminate the null case. if (text1_length == 0 or text2_length == 0) { return 0;