Skip to content

Commit 28844c5

Browse files
authored
perf: optimize the WorkingCopy.IsChanged() method (#1418)
* 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.
1 parent f88652f commit 28844c5

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/ViewModels/WorkingCopy.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,16 +1778,11 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
17781778
if (old.Count != cur.Count)
17791779
return true;
17801780

1781-
var oldMap = new Dictionary<string, Models.Change>();
1782-
foreach (var c in old)
1783-
oldMap.Add(c.Path, c);
1784-
1785-
foreach (var c in cur)
1781+
for (int idx = 0; idx < old.Count; idx++)
17861782
{
1787-
if (!oldMap.TryGetValue(c.Path, out var o))
1788-
return true;
1789-
1790-
if (o.Index != c.Index || o.WorkTree != c.WorkTree)
1783+
var o = old[idx];
1784+
var c = cur[idx];
1785+
if (o.Path != c.Path || o.Index != c.Index || o.WorkTree != c.WorkTree)
17911786
return true;
17921787
}
17931788

0 commit comments

Comments
 (0)