From 25d6c7cc108bea4c81e124623bcf7f4b6832a914 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sat, 19 Aug 2023 23:21:49 +0200 Subject: [PATCH] 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 Reviewed-by: Mike Frysinger Commit-Queue: Sylvain Desodt --- manifest_xml.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/manifest_xml.py b/manifest_xml.py index d944b409..458dfb7d 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -2210,7 +2210,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md toProjects = manifest.paths fromKeys = sorted(fromProjects.keys()) - toKeys = sorted(toProjects.keys()) + toKeys = set(toProjects.keys()) diff = { "added": [], @@ -2221,13 +2221,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md } 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 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md 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