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>
This commit is contained in:
Sylvain 2023-08-19 23:21:49 +02:00 committed by LUCI
parent f19b310f15
commit 25d6c7cc10

View File

@ -2210,7 +2210,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
toProjects = manifest.paths toProjects = manifest.paths
fromKeys = sorted(fromProjects.keys()) fromKeys = sorted(fromProjects.keys())
toKeys = sorted(toProjects.keys()) toKeys = set(toProjects.keys())
diff = { diff = {
"added": [], "added": [],
@ -2221,13 +2221,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
} }
for proj in fromKeys: for proj in fromKeys:
fromProj = fromProjects[proj]
if proj not in toKeys: if proj not in toKeys:
diff["removed"].append(fromProjects[proj]) diff["removed"].append(fromProj)
elif not fromProjects[proj].Exists: elif not fromProj.Exists:
diff["missing"].append(toProjects[proj]) diff["missing"].append(toProjects[proj])
toKeys.remove(proj) toKeys.remove(proj)
else: else:
fromProj = fromProjects[proj]
toProj = toProjects[proj] toProj = toProjects[proj]
try: try:
fromRevId = fromProj.GetCommitRevisionId() fromRevId = fromProj.GetCommitRevisionId()
@ -2239,8 +2239,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
diff["changed"].append((fromProj, toProj)) diff["changed"].append((fromProj, toProj))
toKeys.remove(proj) toKeys.remove(proj)
for proj in toKeys: diff["added"].extend(toProjects[proj] for proj in sorted(toKeys))
diff["added"].append(toProjects[proj])
return diff return diff