perf: optimize the WorkingCopy.IsChanged() method (#1418)
Some checks failed
Continuous Integration / Build (push) Has been cancelled
Continuous Integration / Prepare version string (push) Has been cancelled
Continuous Integration / Package (push) Has been cancelled

* 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.
This commit is contained in:
Göran W 2025-06-13 13:23:20 +02:00 committed by GitHub
parent f88652ffdd
commit 28844c59cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1778,16 +1778,11 @@ namespace SourceGit.ViewModels
if (old.Count != cur.Count)
return true;
var oldMap = new Dictionary<string, Models.Change>();
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;
}