From be2d737c4577f7dfb25c63cb265c2861c7fcf258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Fri, 13 Jun 2025 12:46:08 +0200 Subject: [PATCH] Optimize the WorkingCopy.IsChanged() method * There's no need to populate a Dictionary just to diff the the "old" and "cur" Lists of Changes. * If the two lists are of equal length and no change has occurred, we can assume that they are also reported in equal sort-order (by git-status). * Thus, we only need to compare the two items at each successive index. --- src/ViewModels/WorkingCopy.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index b7dee5c9..09ebc6f6 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1778,16 +1778,11 @@ private bool IsChanged(List old, List cur) if (old.Count != cur.Count) return true; - var oldMap = new Dictionary(); - foreach (var c in old) - oldMap.Add(c.Path, c); - - foreach (var c in cur) + for (int idx = 0; idx < old.Count; idx++) { - if (!oldMap.TryGetValue(c.Path, out var o)) - return true; - - if (o.Index != c.Index || o.WorkTree != c.WorkTree) + var o = old[idx]; + var c = cur[idx]; + if (o.Path != c.Path || o.Index != c.Index || o.WorkTree != c.WorkTree) return true; }