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.
pull/45164/head
characteristic 6 years ago committed by Brian Coca
parent 4e9b8136c2
commit 324b57d6ae

@ -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

Loading…
Cancel
Save