Inspectopedia
 
2024.3

Call to 'set.removeAll(list)' may work slowly

Warning
New
Last modified: 03 December 2024

Reports calls to java.util.Set.removeAll() with a java.util.List argument.

Such a call can be slow when the size of the argument is greater than or equal to the size of the set, and the set is a subclass of java.util.AbstractSet. In this case, List.contains() is called for each element in the set, which will perform a linear search.

Example:

After the quick fix is applied:

New in 2020.3