manifest_xml: use a set instead of (sorted) list in projectsDiff
The logic in projectsDiff performs various operations which
suggest that a set is more appropriate than a list:
- membership lookup ("in")
- removal
Also, sorting can be performed on the the remaining elements at the
end (which will usually involve a much smaller number of elements).
(The performance gain is invisible in comparison to the time being
spent performing git operations).
Cosmetic chance:
- the definition of 'fromProj' is moved to be used in more places
- the values in diff["added"] are added with a single call to extend
Change-Id: I5ed22ba73b50650ca2d3a49a1ae81f02be3b3055
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383434
Tested-by: Sylvain Desodt <sylvain.desodt@gmail.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Sylvain Desodt <sylvain.desodt@gmail.com>
diff --git a/manifest_xml.py b/manifest_xml.py
index d944b40..458dfb7 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -2210,7 +2210,7 @@
toProjects = manifest.paths
fromKeys = sorted(fromProjects.keys())
- toKeys = sorted(toProjects.keys())
+ toKeys = set(toProjects.keys())
diff = {
"added": [],
@@ -2221,13 +2221,13 @@
}
for proj in fromKeys:
+ fromProj = fromProjects[proj]
if proj not in toKeys:
- diff["removed"].append(fromProjects[proj])
- elif not fromProjects[proj].Exists:
+ diff["removed"].append(fromProj)
+ elif not fromProj.Exists:
diff["missing"].append(toProjects[proj])
toKeys.remove(proj)
else:
- fromProj = fromProjects[proj]
toProj = toProjects[proj]
try:
fromRevId = fromProj.GetCommitRevisionId()
@@ -2239,8 +2239,7 @@
diff["changed"].append((fromProj, toProj))
toKeys.remove(proj)
- for proj in toKeys:
- diff["added"].append(toProjects[proj])
+ diff["added"].extend(toProjects[proj] for proj in sorted(toKeys))
return diff