Files
openide/java/java-impl/resources/inspectionDescriptions/SlowAbstractSetRemoveAll.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

27 lines
814 B
HTML

<html>
<body>
Reports calls to <code>java.util.Set.removeAll()</code> with a <code>java.util.List</code> argument.
<p>
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 <code>java.util.AbstractSet</code>.
In this case, <code>List.contains()</code> is called for each element in the set, which will perform a linear search.
</p>
<p><b>Example:</b></p>
<pre><code>
public void check(String... ss) {
// possible O(n^2) complexity
mySet.removeAll(List.of(ss));
}
</code></pre>
<p>After the quick fix is applied:</p>
<pre><code>
public void check(String... ss) {
// O(n) complexity
List.of(ss).forEach(mySet::remove);
}
</code></pre>
<!-- tooltip end -->
<p><small>New in 2020.3</small></p>
</body>
</html>