From 789e3cf6a23fa3b7cc3ea1b8ab95d241d0a6e677 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 28 Jul 2021 15:26:41 +0800 Subject: [PATCH] optimize: limit number of character diff; ignore empty changes --- src/Commands/Diff.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 5128b341..6195d8c4 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -77,10 +77,13 @@ namespace SourceGit.Commands { for (int i = added.Count - 1; i >= 0; i--) { var left = deleted[i]; var right = added[i]; + var result = DiffPlex.Differ.Instance.CreateCharacterDiffs(left.Content, right.Content, false, false); + if (result.DiffBlocks.Count > 4) break; + foreach (var block in result.DiffBlocks) { - left.Highlights.Add(new Models.TextChanges.HighlightRange(block.DeleteStartA, block.DeleteCountA)); - right.Highlights.Add(new Models.TextChanges.HighlightRange(block.InsertStartB, block.InsertCountB)); + if (block.DeleteCountA > 0) left.Highlights.Add(new Models.TextChanges.HighlightRange(block.DeleteStartA, block.DeleteCountA)); + if (block.InsertCountB > 0) right.Highlights.Add(new Models.TextChanges.HighlightRange(block.InsertStartB, block.InsertCountB)); } } }