Correct Jinja2 plugin math filter symmetric_difference() to not repeatedly (#45093)

build its intersection set and unnecessarily unique the final result.

The prior use of the intersect() function within the list comprehension
conditional leads to the function being called for every value in the input
list being processed, not efficient.  When the input lists a,b are large,
the Ansible run time and resource utilization wildly increases generally
never completing the operation.

Unique of the intersection result is unnecessary as the source list union()
is already unique.
This commit is contained in:
characteristic 2018-09-04 08:12:02 -05:00 committed by Brian Coca
parent 4e9b8136c2
commit 324b57d6ae

View file

@ -65,7 +65,8 @@ def symmetric_difference(a, b):
if isinstance(a, collections.Hashable) and isinstance(b, collections.Hashable):
c = set(a) ^ set(b)
else:
c = unique([x for x in union(a, b) if x not in intersect(a, b)])
isect = intersect(a, b)
c = [x for x in union(a, b) if x not in isect]
return c